进一步推进 TEI 勘探。这是我的 XML Tei 文件,其中包含具有不同属性(时间、从、到)的“日期”节点。
我已经使用成功提取了“when”属性的值
dateWhen<-unlist(xpathApply(doc, '//date', xmlGetAttr,"when"))
但现在我想同时提取“from”和“to”属性的值,并且 xmlGetAttr 不超过一个属性。
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="parser.xsl" type="text/xsl"?>
<TEI xmlns="http://www.tei-c.org/ns/1.0">
<teiHeader>
<fileDesc>
</fileDesc>
</teiHeader>
<text>
<body>
<p><date when="1715-01-07">Du 7e Janvier.</date> Un ambassadeur extraordinaire du roi.</p>
<p><date from="1715-12-13" to="1715-12-27">Dudit mois de décembre</date> Quelque temps avant la fin du mois</p>
</body>
</text>
</TEI>
我试过这个
dateFromTo<-unlist(xpathApply(doc, '//date', xmlAttrs,c("from","to")))
但我获取了日期节点的所有属性
而且这也不起作用
frames<-getNodeSet(doc, '//date')
dateFromTo<-xmlAttrs(frames[[1]]) [c('from','to')]
与 NULL 响应
有人可以帮忙吗?谢谢
你不能做这样的事情吗
sapply(c("when","from"), function(x) xpathSApply(doc, '//date', xmlGetAttr, x))
对于可重现的示例,我将使用 xml 格式的 PLOS One 文章。
library(XML)
doc <- xmlParse("http://www.plosone.org/article/fetchObjectAttachment.action?uri=info%3Adoi%2F10.1371%2Fjournal.pone.0084312&representation=XML")
sapply(c("contrib-type","xlink:type"), function(x) xpathSApply(doc, '//contrib', xmlGetAttr, x))
contrib-type xlink:type
[1,] "author" "simple"
[2,] "author" "simple"
[3,] "author" "simple"
[4,] "author" "simple"
[5,] "author" "simple"
[6,] "editor" "simple"
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)