我想传入一个 xpath 查询并返回我找到的值。我正在寻找一个属性的值。
_query = "//@RequestType";
我可以取回节点,但我不确定如何从中获取字符串值。我想查询以下 xml 的type
属性并返回“xpath”。
如果我可以替换我的查询并从 nice 中获取值“yes”,那也很好。
<?xml version="1.0" ?>
<test type="xpath">
<nice>yes</nice>
</test>
C#
public string Locate(string message)
{
using (var stream = new MemoryStream(Encoding.GetBytes(message)))
{
var doc = new XPathDocument(stream);
var nav = doc.CreateNavigator();
var result = nav.Select(_query);
if (result != null)
{
return result
}
}
}