包含正斜杠(/)的屬性的XPath查詢

[英]XPath query for an attribute containing forward slash (/)


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.

我正在嘗試使用XPath表達式在XMLDocument上執行SelectSingleNode。但是,當我搜索的屬性值包含多個正斜杠(/)時,它返回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

<?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)

此XPath表達式返回正確的節點(例如:上面示例中的第一個節點)

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

This XPath expression returns null

此XPath表達式返回null

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

I'm in a C#, .net 3.5 environment.

我在C#,.net 3.5環境中。

EDIT: Thanks for the responses. I solved the issue by using a double forward slash in the select expression.

編輯:感謝您的回復。我通過在select表達式中使用雙正斜杠解決了這個問題。

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

1 个解决方案

#1


0  

Thanks for the responses. I solved the issue by using a double forward slash in the select expression.

謝謝你的回復。我通過在select表達式中使用雙正斜杠解決了這個問題。

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

注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2011/05/05/60d2a789317a9c37cc5ab27f0f009640.html



 
  © 2014-2022 ITdaan.com 联系我们: