職場の同僚が、クエリを実行しようとしたときに非常に珍しい XML ファイルで問題が発生しました。彼を助けようとした後、私と他の人たちは少し創造的なブロックに陥っています....これを見て、興味があるかもしれませんここにたくさんの人が……。
構造:
<Root>
<MainFoo>
<Foo>
<A bla="bla" />
<B bla1="blablabla" />
<C bla2="blabla" />
<Bar N="Education" V="Some Text" />
<Bar N="Other Node" V="Some other Text" />
<Bar N="Yet Other Node" V="Some other other Text" />
<Bar N="fourth Bar Node" V="Some other other otherText" />
<Bar N="UserID" V="1" />
</Foo>
<Foo>
<A bla="bla" />
<B bla1="blablabla" />
<C bla2="blabla" />
<Bar N="Education" V="Specific Text" />
<Bar N="Other Node" V="Some other Text" />
<Bar N="Yet Other Node" V="Some other other Text" />
<Bar N="fourth Bar Node" V="Some other other otherText" />
<Bar N="UserID" V="2" />
</Foo>
<Foo>
<A bla="bla" />
<B bla1="blablabla" />
<C bla2="blabla" /> <!--***No Bar node with N="Education" in this Foo Node, not a mistake! this might be part of the problem but this is the XML Structure and can't be changed***-->
<Bar N="Other Node" V="Some other Text" />
<Bar N="Yet Other Node" V="Some other other Text" />
<Bar N="fourth Bar Node" V="Some other other otherText" />
<Bar N="UserID" V="3" />
</Foo>
<Foo>
<A bla="bla" />
<B bla1="blablabla" />
<C bla2="blabla" />
<Bar N="Education" V="Specific Text" />
<Bar N="Other Node" V="Some other Text" />
<Bar N="Yet Other Node" V="Some other other Text" />
<Bar N="fourth Bar Node" V="Some other other otherText" />
<Bar N="UserID" V="4" />
</Foo>
</MainFoo>
<OtherMainFoo></OtherMainFoo>
<MoreMainFoo></MoreMainFoo>
</Root>
さて、目前の問題について: LINQ to XML を使用して、すべてのユーザー ノードのすべてのユーザー ID 値をすべてのFoo 要素 の文字列に取得しようとしていますIFこのFoo にはBar ノードがあり、このBar ノードの N 属性があります「教育」であり、属性教育を持つこのバーノードに、LINQ で指定した単語を含まない値を持つ V がある場合のみ
たとえば、教育を持つ Foo ノードのすべてのユーザー ID に「Some」という単語が含まれないようにする場合、2,4 という結果が得られます。 V アトリビュートに Some 文字列があり、Foo 番号 3 がある N アトリビュートに Education 値がある Bar ノードがない (非常に重要です。これが常に空の結果を取得する理由の 1 つだと考えているためです。私たちがすることはありません)。
アイデアをお持ちの LINQ to XML の専門家なら誰でも、これは XML の非常に珍しいシナリオですが、対処しなければならないことであり、この質問はここにいる多くの人々の関心を引くでしょう。