LookupNamespace() public method

public LookupNamespace ( string prefix ) : string
prefix string
return string
Example #1
0
		// FIXME: add a bunch of annoying datetime functions

		public static object FnResolveQName (string qname, XPathNavigator element)
		{
			if (qname == null)
				return null;

			int index = qname.IndexOf (':');
			string prefix = (index < 0) ? "" : qname.Substring (index);
			return new XmlQualifiedName (
				element.LookupNamespace (prefix),
				index < 0 ? qname : qname.Substring (index + 1));
		}
 string IXmlNamespaceResolver.LookupNamespace(string prefix)
 {
     return(_nav.LookupNamespace(prefix));
 }
        public static string MSNamespaceUri(string name, XPathNavigator currentNode) {
            int colonOffset;
            int len = ValidateNames.ParseQName(name, 0, out colonOffset);

            if (len != name.Length) {
                return string.Empty;
            }
            string prefix = name.Substring(0, colonOffset);
            if (prefix == "xmlns") {
                return string.Empty;
            }
            string ns = currentNode.LookupNamespace(prefix);
            if (ns != null) {
                return ns;
            }
            if (prefix == "xml") {
                return XmlReservedNs.NsXml;
            }
            return string.Empty;
        }
 /// <summary>
 /// This method resolves the prefix of an argument.
 /// If a prefix is found, the corresponding namespace URI (if existing) is looked up 
 /// and substituted. Otherwise the target namespace is placed first.
 /// </summary>
 /// <param name="args">An argument of the function to be resolved</param>
 /// <param name="xsltContext">The Xslt context for namespace resolving</param>
 private string resolveNsPrefix(string args, string targetNs, XPathNavigator docContext)
 {
     string prefix;
     string ns;
     if (args.Contains(":"))
     {
         prefix = args.Substring(0, args.IndexOf(":"));
         if (!string.IsNullOrEmpty((ns = docContext.LookupNamespace(prefix))))
             return args = args.Replace(prefix + ":", ns);
         return targetNs + args;
     }
     return targetNs + args;
 }
Example #5
0
        public void ReadXml(XPathNavigator node, XmlResolver resolver)
        {
            if (node.NodeType == XPathNodeType.Element) {

            XPathNavigator el = node.Clone();

            if (node.MoveToFirstAttribute()) {

               do {
                  switch (node.LocalName) {
                     case "byte-order-mark":
                        this.ByteOrderMark = node.ValueAsBoolean;
                        break;

                     case "doctype-public":
                        this.DocTypePublic = node.Value;
                        break;

                     case "doctype-system":
                        this.DocTypeSystem = node.Value;
                        break;

                     case "encoding":
                        this.Encoding = Encoding.GetEncoding(node.Value);
                        break;

                     case "indent":
                        this.Indent = node.ValueAsBoolean;
                        break;

                     case "media-type":
                        this.MediaType = node.Value;
                        break;

                     case "method":

                        if (node.Value.Contains(":")) {

                           string name = XmlConvert.VerifyName(node.Value);
                           string[] parts = name.Split(':');

                           string local = parts[1];
                           string ns = node.LookupNamespace(parts[0]) ?? "";

                           XmlQualifiedName qname = new XmlQualifiedName(local, ns);

                           if (ns != null
                              && (qname == ExtensionMethods.Base64Binary
                                 || qname == ExtensionMethods.HexBinary)) {
                              this.Method = qname;
                           } else {
                              throw new ArgumentException("The value of the method attribute must be one of: xml, html, xhtml, text, http:base64Binary or http:hexBinary.", "node");
                           }

                        } else {

                           switch (node.Value) {
                              case "xml":
                                 this.Method = XPathSerializationMethods.Xml;
                                 break;

                              case "html":
                                 this.Method = XPathSerializationMethods.Html;
                                 break;

                              case "xhtml":
                                 this.Method = XPathSerializationMethods.XHtml;
                                 break;

                              case "text":
                                 this.Method = XPathSerializationMethods.Text;
                                 break;

                              default:
                                 throw new ArgumentException("The value of the method attribute must be one of: xml, html, xhtml, text, http:base64Binary or http:hexBinary.", "node");
                           }
                        }
                        break;

                     case "omit-xml-declaration":
                        this.OmitXmlDeclaration = node.ValueAsBoolean;
                        break;

                     case "src":

                        Uri elBaseUri = !String.IsNullOrEmpty(el.BaseURI) ?
                           new Uri(el.BaseURI) :
                           null;

                        if (resolver != null) {
                           this.Src = resolver.ResolveUri(elBaseUri, node.Value);
                        } else {
                           this.Src = (elBaseUri != null) ?
                              new Uri(elBaseUri, node.Value) :
                              new Uri(node.Value);
                        }

                        break;

                     default:
                        break;
                  }

               } while (node.MoveToNextAttribute());

               node.MoveToParent();
            }

            if (node.MoveToFirstChild()) {

               do {
                  if (node.NodeType == XPathNodeType.Element || node.NodeType == XPathNodeType.Text) {
                     this.Content = node.Clone();
                     break;
                  }

               } while (node.MoveToNext());

               node.MoveToParent();
            }
             }
        }
Example #6
0
 /// <summary>
 /// This method resolves the prefix of an argument.
 /// If a prefix is found, the corresponding namespace URI (if existing) is looked up 
 /// and substituted. Otherwise the target namespace is placed first.
 /// </summary>
 /// <param name="args">An argument of the function to be resolved</param>
 /// <param name="targetNs">The target namespace</param>
 /// <param name="docContext">The document context</param>
 private static string ResolveNsPrefix(string args, string targetNs, XPathNavigator docContext)
 {
     if (args.Contains(":"))
     {
         var prefix = args.Substring(0, args.IndexOf(":", StringComparison.Ordinal));
         string ns;
         if (!string.IsNullOrEmpty((ns = docContext.LookupNamespace(prefix))))
             return args.Replace(prefix + ":", ns);
         return targetNs + args;
     }
     return targetNs + args;
 }