一位同事在工作時遇到了一個非常不尋常的XML文件問題,當試圖查詢它並試圖幫助他時,我和其他人都在創意塊....看看這個,它可能感興趣的很多人在這裏....複雜的XML結構很難用LINQ查詢到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>
OK,現在手頭的問題: 我們正在與LINQ努力XML獲取每個用戶ID值對於每個用戶節點成爲每個字符串Foo元素IF有這美孚一杆節點這杆節點的N屬性是「教育」且僅當與屬性教育這個杆節點都有一個值在V不是包含了我們在LINQ
例如指定,如果我們希望所有用戶ID爲富教育節點不包含單詞「一些」我們將得到的2,4結果的話因爲Foo第一個有一個酒吧具有N屬性的教育值的節點,但它在V屬性和Foo編號中具有一些字符串3在N屬性中沒有具有教育值的條形節點(非常重要,因爲我們認爲這是其中一個原因我們總是空着的,結果是我們做了什麼)。
任何LINQ to XML專家在這裏有一個想法,這是一個非常不尋常的XML場景,但那是我們必須處理的,而且這個問題會引起很多人的興趣。
不同於論壇的網站,我們不使用「謝謝」,或者「任何幫助表示讚賞「,或簽名[so]。請參見「[應‘你好’,‘謝謝’標語,並稱呼從撤職?](http://meta.stackexchange.com/questions/2950/should-hi-thanks-taglines-and-salutations-be -removed - 從 - 個)。 –
有沒有理由使用LINQ這個任務嗎?這裏的業務規則聽起來更適合的System.Xml – Hogan
首先,不會再發生了約翰,霍根,爲什麼不使用LINQ?它應該做System.xml所做的每件事情來查詢XML Structure,但速度更快,代碼行更少,速度更快,或者我錯了嗎?是不是圍繞LINQ to XML的所有想法?爲什麼使用XML Node查詢這裏,那麼LINQ – Erez