2016-04-22 82 views
-2

我有一個XML文件,我想讀它,並顯示我的XML的某些部分以列表:在第一閱讀複雜的XML文件

<collection> 
<source/> 
<date/> 
<key/> 
<document> 
    <id>AIMed_d30</id> 
    <passage> 
     <offset>0</offset> 
     <text>Isolation of human delta-catenin and its binding specificity with presenilin 1. We screened proteins for interaction with presenilin (PS) 1, and cloned the full-length cDNA of human delta-catenin. </text> 
     <annotation id="T1"> 
     <infon key="file">ann</infon> 
     <infon key="type">protein</infon> 
     <location length="13" offset="19"/> 
     <text>delta-catenin</text> 
     </annotation> 
     <relation id="R4"> 
     <infon key="relation type">Interaction</infon> 
     <infon key="file">ann</infon> 
     <infon key="type">Relation</infon> 
     <node role="Arg1" refid="T12"/> 
     <node role="Arg2" refid="T13"/> 
     </relation> 
    </passage> 
    </document> 

我想讀整個XML文件,然後我想要顯示部分:「collection/document/id/passage/annotation/text」並將其他部分保存爲字符串。 我搜索網絡和計算器,但它並沒有幫助我,也沒有得到我想要的答案。

如果你能幫助我,我將非常感激。

+3

您的XML不看良好的。沒有關閉標籤,並且標籤也不是標籤的子標籤,因此沒有從的路徑來使您的「/ id/passage」xpath正常工作。 – PhillipH

+0

_「並將其他部分保存爲字符串」_不是很清楚。 –

+1

'但它沒有幫助我,也沒有得到我想要的答案'你找到了什麼樣的答案?你想要什麼樣的答案?我問的原因是因爲如果我要回答你的問題,我會給你同樣類型的linq-to-xml基礎答案,我之前在這裏發佈過,但我不確定它會滿足你的需求。 –

回答