0
私は以下のようなXMLを持っています。パスがd:\ mypathのときにタイトルを取得する必要があります。私は1つ下にしようとしましたが、期待通りには与えていません。 LINQ to XMLに実装したいと思います。兄弟ノードを取得するlinq
マイコード:
string a = (string)xdoc.XPathSelectElement(
"//child/content[path='" + mypath + "']/../doc_attributes/title");
サンプルXML::
<parent>
<doc>
<order>testorder</order>
<preorder>yes</preorder>
</doc>
<childs>
<child>
<doc_attributes>
<id>090015b3804fb931</id>
<title>CTA</title>
</doc_attributes>
<content>
<path>D:\\Mypath</path>
</content>
</child>
</childs>
</parent>
今、私は以下のように
XPathSelectElement
を使用して、私の仕事を終えたが、私はLINQクエリ内に興味がありますについては
XDocument xdoc = XDocument.Load(file);
string mypath = @"D:\\Mypath";
var result = xdoc.Descendants("child")
.Where(i => (string)i.Element("content").Element("path") == mypath)
.Select(i => (string)i.Element("title")).FirstOrDefault();