/// <summary> /// Resolves a <see cref="XName"/> from the given prefixed name, given the specified <see cref="XObject"/>'s /// naming context. /// </summary> /// <param name="self"></param> /// <param name="prefixedName"></param> /// <returns></returns> public static XName ResolvePrefixedName(this XObject self, string prefixedName) { Contract.Requires <ArgumentNullException>(self != null); Contract.Requires <ArgumentNullException>(prefixedName != null); var i = prefixedName.IndexOf(':'); if (i == -1) { return(self.GetNamespaceOfPrefix("") + prefixedName); } var prefix = prefixedName.Substring(0, i); if (string.IsNullOrWhiteSpace(prefix)) { prefix = ""; } var localName = prefixedName.Substring(i + 1); if (string.IsNullOrWhiteSpace(localName)) { localName = ""; } var ns = self.GetNamespaceOfPrefix(prefix); if (ns == null) { throw new NullReferenceException(); } return(ns + localName); }
public override string LookupNamespace(string prefix) { // default prefix resolve to default namespace if (prefix == "") { return(""); } return(xml.GetNamespaceOfPrefix(prefix).NamespaceName); }