private static XmlQualifiedName ValueAsQName(XmlAttribute attribute) { if (attribute == null) { return(null); } // split QName into prefix and local name string[] pieces = attribute.Value.Split(':'); if (pieces.Length < 2) { // unprefixed name pieces = new string[] { string.Empty, pieces[0] }; } else if (pieces.Length > 2) { // actually, this is not a valid QName - be lenient pieces = new string[] { pieces[0], attribute.Value.Substring(pieces[0].Length + 1) }; } return(new XmlQualifiedName(pieces[1] ?? string.Empty, attribute .GetNamespaceOfPrefix(pieces[0]))); }
public static StatusCode Parse(XmlElement statusCode) { XmlNamespaceManager nsmngr = new XmlNamespaceManager(statusCode.OwnerDocument.NameTable); nsmngr.AddNamespace("samlp", samlp); XmlAttribute statusCodeValue = statusCode.Attributes["Value"]; if (statusCodeValue == null) { throw new SamlException("sampl:StatusCode does not contain a Value attribute"); } String[] parts = statusCodeValue.Value.Split(':'); String codeValueNs; String codeValueLocal; switch (parts.Length) { case 1: codeValueNs = statusCodeValue.GetNamespaceOfPrefix(""); codeValueLocal = parts[0]; break; case 2: codeValueNs = statusCodeValue.GetNamespaceOfPrefix(parts[0]); codeValueLocal = parts[1]; break; default: throw new SamlException(String.Format("Illegal sampl:StatusCode/@Value content: {0}", statusCodeValue.Value)); } StatusCode subStatus = null; XmlElement subStatusCode = (XmlElement)statusCode.SelectSingleNode("samlp:StatusCode", nsmngr); if (subStatusCode != null) { subStatus = Parse(subStatusCode); } return(new StatusCode(codeValueLocal, codeValueNs, subStatus)); }