2016-04-22 90 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基础答案,我之前在这里发布过,但我不确定它会满足你的需求。 –

回答