Lets say I have following:
library(XML)
my.xml <- '
<tv>
<show>
<name>Star Trek TNG</name>
<rating>1.0</rating>
</show>
<show>
<name>Doctor Who</name>
</show>
<show>
<name>Babylon 5</name>
<rating>2.0</rating>
</show>
</tv>
'
doc <- xmlParse(my.xml)
xpathSApply(doc, "/tv/show/rating", xmlValue)
# [1] "1.0" "2.0"
There are three 'show' nodes. How can I instead make the output be:
# [1] "1.0" NULL "2.0"
so as to account for Doctor Who not having a rating in the xml but the length still being 3?