node selection based on content using xpath in R
How can I select the correct node from an xml page when I know that the text in one the daughter node contains a certain string.
library(XML)
xml = htmlTreeParse("http://legeforeningen.no/id/1712", useInternalNodes=TRUE)
names<-xpathSApply(xml, "//p[4]/text()", xmlValue)
Thus, in this 开发者_Go百科example I know that the correct paragraph is 4. But I´d prefer to condition this on containing the text "Totalt antall godkjente". Hence an expression like
xpathApply(xml, "//p[contains(text(),'Totalt antall godkjente')]/text()", xmlValue)
would be great. But this doesnt work and I guess it is because this is just a part of a long string (?). Any ideas how this can be done?
Found it..
xpathApply(xml, "//p[contains(.,'Totalt antall godkjente')]/text()", xmlValue)..
精彩评论