2

I have created an XML tree using the XML package in R, when saving using 'saveXML' the encoding argument is ignored.

here is an example

   xml1 <- xmlTree()
   xml1$addTag("Data","Hello World")

   saveXML(xml1,filepath, encoding = "UTF-8")

the result is as follows:

    <?xml version="1.0"?>
    <Data>Hello World</Data>

however I was expecting the top line to read:

    <?xml version="1.0" encoding="UTF-8"?>

any help would be appreciated

3
  • I was reading help on saveXML and it seems prefix attribute can be used to add that information. Try saveXML(xml1,filepath, prefix = '<?xml version="1.0" encoding="UTF-8"?>\n'). Please read help to understand the explanation. Commented Sep 1, 2017 at 19:44
  • Maybe because UTF-8 is the default? stackoverflow.com/questions/16361909/… Commented Sep 1, 2017 at 20:02
  • Typo? Your sample code says ecoding = "UTF-8" not encoding = "UTF-8" Commented Sep 1, 2017 at 20:54

1 Answer 1

1

The saveXML function has a prefix= parameter that you can use to set the header

saveXML(xml1, filepath, prefix='<?xml version="1.0" encoding="UTF-8"?>\n')
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.