Can anyone provide an example of using the XmlDocument.SelectSingleNodeNS function for WinRT? I'm unclear what the second parameter is expecting and I can't find an example.
public IXmlNode SelectSingleNodeNS(
string xpath,
object namespaces
)
Contains a string that specifies the namespaces to use in XPath expressions when it is necessary to define new namespaces externally. Namespaces are defined in the XML style, as a space-separated list of namespace declaration attributes. You can use this property to set the default namespace as well.
The namespaces parameter is obviously just a string (although declared as object) that must contain an XML namespace declaration in the form "xmlns:aliasname='namespace'" (the XML style). For example
xmlDocument.DocumentElement.SelectNodesNS("cb:person",
"xmlns:cb='http://www.addison-wesley.de/codebook'");
works with an XML document like this:
<?xml version="1.0" encoding="utf-8" ?>
<persons xmlns="http://www.addison-wesley.de/codebook">
<person id="1000">
<firstname>Zaphod</firstname>
<lastname>Beeblebrox</lastname>
<type>Alien</type>
</person>
...
</persons>
Note that the alias (cb:) was used in the XPath.
If the namespace is not in the XML style you get the infamous COM error E_Fail.
The (poor) documentation of SelectNodesNS says: "Contains a string that specifies namespaces for use in XPath expressions when it is necessary to define new namespaces externally. Namespaces are defined in the XML style, as a space-separated list of namespace declaration attributes. You can use this property to set the default namespace as well."
According to that namespaces must be a string and could contain more than one XML namespace (did not try that yet). Still the question is open why it is an object.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With