を使用して行にあるかどうかを知るためにどのように私はこの単純なXMLC#の2つの要素は、XML LINQ
<parent>
<child>
<son attribute="1"/>
<sp>
<son attribute="2"/>
<sp>
</child>
<child>
<another child>
<son attribute ="3"/>
<sp>
</another child>
</child>
<child>
<son attribute="5"/>
</child>
</parent>
ここに私のコードは今のところですがあります。実際に私は、出力が
<parent>
<child>
<son attribute="1"/>
<sp value="1">
<son attribute="2"/>
<sp value="2">
</child>
<child>
<another child>
<son attribute ="3"/>
<sp value="3">
</another child>
</child>
<child>
<son attribute="5"/>
</child>
</parent>
になります私の問題は、お互いにその隣場合son
とsp
タグは、隣接している場合はどのように私はチェックしないで次の
XDocument doc = XDocument.Parse(string);
foreach (var el in doc.Descendants("child").ToList())
{
}
何を知りません、sp
タグは。これは、あなたがそれを行う方法ですson
タグ
で有効な形式を持っていることを確認する必要があります。私はしばらくXSLTを使用していないが、C#は間違いなくそれをサポートしているので、これらのSOの質問は助けになるかもしれない:http://stackoverflow.com/questions/23274312/how-to-match-and-wrap-identical-and-隣接ノードと一緒にxslt-1-0とhttp://stackoverflow.com/questions/32701706/xslt-identify-consecutive-nodes-which-has-same-patters-of-attribute-values – user783836
それは息子の隣ではない? – DarkKnight
@DarkKnight何も起こりません、例 – imadammy