xpathクエリを渡して、見つけたものの値を返したいのですが。特に属性の値を探しています。
_query = "//@RequestType";
ノードを取り戻すことはできますが、文字列値を取得する方法がわかりません。type
次のxmlでその属性を照会し、「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
}
}
}