在R中选择特定的XML节点?

前端之家收集整理的这篇文章主要介绍了在R中选择特定的XML节点?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我在R中使用 XML包来解析具有以下结构的 XML文件.

<document id="Something" origId="Text">
    <sentence id="Something" origId="thisorig" text="Blah Blah.">
    <special id="id.s0.i0" origId="1" e1="en1" e2="en2" type="" directed="True"/>
    </sentence>
     <sentence id="Something" origId="thisorig" text="Blah Blah.">
      </sentence>
</document>

我想选择具有< / special>的节点在一个变量和没有< / special>的节点中标记它们标记在其他变量中.

是否可以用R做任何指针/答案将非常有帮助.

解决方法

添加了一些案例来测试异常:

<document id="Something" origId="Text">
    <sentence id="Something" origId="thisorig" text="Blah Blah.">
    <special id="id.s0.i0" origId="1" e1="en1" e2="en2" type="" directed="True"/>
    </sentence>
    <sentence id="Else" origId="thatorig" text="Blu Blu.">
      <special id="id.s0.i1" origId="1" e1="en1" e2="en2" type="" directed="True"/>
    </sentence>
     <sentence id="Something" origId="thisorig" text="Blah Blah.">
       <notso id = "hallo" />
      </sentence>
     <sentence id="Something no sentence" origId="thisOther" text="Blah Blah.">
      </sentence>
</document>

library(XML)
doc = xmlInternalTreeParse("sentence.xml")
hasSentence = xpathApply(doc,"//sentence/special/..")
xpathApply(doc,"/document/sentence[not(child::special)]")

猜你在找的XML相关文章