0

I am trying to find the value of nodes associated with attributes that are described using single quotes using the R package XML. For example, a node A has an attribute Name="Hello 'World'".

I create a character vector

s = "//A[@Name='Hello 'World'']" 

and then use xpathApply(top,s,xmlValue) to try to get the information. I get an xpath error because the single quotes end the attribute string prematurely. Does anyone have a suggestion.

Thanks,

neilfws
  • 32,751
  • 5
  • 50
  • 63

1 Answers1

0

Given

library(XML)
top <- xmlParse('<A Name="Hello \'World\'">foo</A>')

You can do s <- "//A[@Name=\"Hello 'World'\"]" or s <- '//A[@Name=concat("Hello ", "\'World\'")]' (see here) to get

xpathApply(top,s,xmlValue)
# [[1]]
# [1] "foo"
lukeA
  • 53,097
  • 5
  • 97
  • 100