I'm trying to do a SelectSingleNode
on an XMLDocument
using an XPath expression. However, when the attribute value that I'm searching contains multiple forward slashes (/), it returns null.
I can't find any resources online for escaping the forward slash. Does anyone know a way around this? Or have I got my syntax all wrong for matching the attribute value?
Example XML
<?xml version="1.0"?>
<Root>
<Page Path="/brand" />
<Page Path="/brand/armada" />
</Root>
This XPath expression returns the correct node (e.g.: the first one in the above sample)
XmlNode N = xmlDoc.SelectSingleNode("Root/Page[@Path='/brand']");
This XPath expression returns null
XmlNode N = xmlDoc.SelectSingleNode("Root/Page[@Path='/brand/armada']");
I'm in a C#, .net 3.5 environment.
EDIT: Thanks for the responses. I solved the issue by using a double forward slash in the select expression.
XmlNode N = xmlDoc.SelectSingleNode("Root//Page[@Path='/brand/armada']");
Thanks for the responses. I solved the issue by using a double forward slash in the select expression.
XmlNode N = xmlDoc.SelectSingleNode("Root//Page[@Path='/brand/armada']");
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