XPath query for an attribute containing a slash (/)

I am trying to do SelectSingleNodeon XMLDocumentusing an XPath expression. However, when the attribute value I'm looking for contains a few forward slashes (/), it returns null.

I cannot find any resources on the Internet to avoid a slash. Does anyone know about this? Or didn’t I get my syntax for incorrect attribute value matching?

XML example

<?xml version="1.0"?>
  <Root>
    <Page Path="/brand" />
    <Page Path="/brand/armada" />
  </Root>

This XPath expression returns the correct node (for example, the first in the example above)

XmlNode N = xmlDoc.SelectSingleNode("Root/Page[@Path='/brand']");

This XPath expression returns null

XmlNode N = xmlDoc.SelectSingleNode("Root/Page[@Path='/brand/armada']");

I am in a C # environment,. Net 3.5.

EDIT: Thanks for the answers. I solved the problem using a double slash in the select statement.

XmlNode N = xmlDoc.SelectSingleNode("Root//Page[@Path='/brand/armada']");
+5
source share
1

. , select.

XmlNode N = xmlDoc.SelectSingleNode("Root//Page[@Path='/brand/armada']");
0

All Articles