R XML select 2 attributes from a same node xmlAttrs()

后端 未结 1 458
北海茫月
北海茫月 2021-01-29 04:40

Going Further in TEI exploration. This is my XML Tei file containing \"date\" nodes with different attributes (when, from, to). I have sucessfully extracted the value of \"when

相关标签:
1条回答
  • 2021-01-29 05:07

    Couldn't you do something like this

    sapply(c("when","from"), function(x) xpathSApply(doc, '//date', xmlGetAttr, x))
    

    For a reproducible example, I'll use a PLOS One article in xml format.

    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"
    
    0 讨论(0)
提交回复
热议问题