0

I am reading XPath-Expressions from an XML-File using readLines and xmlTreeParse, xmlToList from the XML package.

In my XML file there is a line with an XPath like

//*[(@id = "name")]              (1)

The functions mentioned above always add escape chars to my XPath which turns them to

"//*[(@id = \"name\")]"          (2)

How can I convert (2) back to (1)?

I already tried:

  • stringi::stri_unescape_unicode
  • gsub with "\" as pattern which leads to an "Trailing backslash" error
  • gsub with "[\]" which changes nothing
  • some variations of the above using intToUtf8()
  • adding escape \ to my XML file
Andi
  • 124
  • 2
  • 12
  • 1
    You're confusing the default object `print()` output with the actual data in the character vector. Try `print(name_of_your_character_vector, quote=FALSE)` or `cat(name_of_your_character_vector, sep="\n")` to prove it. You can even do `charToRaw(name_of_your_character_vector[1])` (or any index) to see the hex strings. A backslash is `5c`. There won't be any. – hrbrmstr Nov 14 '18 at 14:04
  • 1
    There is nothing to convert, you have `"`s, and not ``\"`` in your strings – Wiktor Stribiżew Nov 14 '18 at 14:11
  • I guess I'm having a different problem with my XPath expressions then as they don't work when passed to my function. Thanks for your help. – Andi Nov 15 '18 at 08:24

0 Answers0