gpt4 book ai didi

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

转载 作者:数据小太阳 更新时间:2023-10-29 02:21:15 24 4
gpt4 key购买 nike

我正在使用 XML包装在 R解析 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 - 在 R 中选择特定的 XML 节点?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5587338/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com