Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This function will add a namespacemanager to your document. Replace "mysite" with whatever you want. After this, you can select nodes with "mysite:[nodename]".</p> <pre><code>public static XmlNamespaceManager AttachNamespaces(ref XmlDocument xmldoc) { XmlNamespaceManager NS = default(XmlNamespaceManager); XmlNode rootnode = default(XmlNode); string strTest = null; string attrname = null; string ns = null; NS = new XmlNamespaceManager(xmldoc.NameTable); rootnode = xmldoc.DocumentElement; strTest = GetAttribute(ref rootnode, "xmlns"); if (string.IsNullOrEmpty(strTest)) { NS.AddNamespace("mysite", "http://www.mysite.com/"); } else { NS.AddNamespace("mysite", strTest); } // Add namespaces from XML root tag foreach (XmlAttribute attr in rootnode.Attributes) { attrname = attr.Name; if (attrname.IndexOf("xmlns:") == 0 &amp;&amp; !string.IsNullOrEmpty(attrname)) { ns = attrname.Substring(7); NS.AddNamespace(ns, attr.Value); } } return NS; } </code></pre> <p>Helper function:</p> <pre><code>public static string GetAttribute(ref XmlNode mynode, string AttributeName, string DefaultValue = "") { XmlAttribute myattr = default(XmlAttribute); string rtn = ""; if (mynode != null) { myattr = mynode.Attributes[AttributeName]; if (myattr != null) { rtn = mynode.Attributes[AttributeName].Value; } } if (string.IsNullOrEmpty(rtn)) rtn = DefaultValue; return rtn; } </code></pre> <p>For instance:</p> <pre><code>XmlDocument xmldoc = new XmlDocument; // Load something into xmldoc XmlNamespaceManager NS = AttachNamespaces(ref XmlDocument xmldoc); XMLNode mynode = xmldoc.SelectSingleNode("//mysite:VersionInfo[@Name='Build']", NS); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload