用于TEI的R xml xpathApply

时间:2014-01-05 14:02:26

标签: xml r

我有一个xml-tei-file.xml看起来像这样:

<?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>
      <revisionDesc>
         <change>
            <name/>
            <date/>
         </change>
      </revisionDesc>
   </teiHeader>
   <text>
      <body>
         <div><p><date when="1715-01-07">Du 7e  Janvier.</date> Un ambassadeur extraordinaire du roi.</p></div> 
        <div><p><date when="1715-12">Dudit mois de décembre</date> Quelque temps avant la fin du mois</p></div>
      </body>
   </text>
</TEI>

我想在=“1715- *”时获取信息 我试过了

library(XML) 
doc<-xmlParse("xml-tei-file.xml")

> getNodeSet(doc, "//date[@when]")
list()
attr(,"class")
[1] "XMLNodeSet"

> unlist(xpathApply(doc, '//date', xmlValue))
NULL 

如何获取日期节点?

1 个答案:

答案 0 :(得分:2)

即将结束,请使用xmlGetAttr

unlist(xpathApply(doc, '//date', xmlGetAttr,"when"))
[1] "1715-01-07" "1715-12"