[R] saveXML() prefix argument
Duncan Temple Lang
dtemplelang at ucdavis.edu
Sat Oct 19 02:22:56 CEST 2013
Hi Earl
Unfortunately, the code works for me, i.e. indents _and_ displays the accented vowels correctly.
Can you send me the output of the function call
libxmlVersion()
and also sessionInfo(), please?
D.
On 10/18/13 10:27 AM, Earl Brown wrote:
> Thanks Duncan. However, now I can't get the Spanish and Portuguese accented vowels to come out correctly and still keep the indents in the saved document, even when I set encoding = "UTF-8":
>
> library("XML")
> concepts <- c("español", "português")
> info <- c("info about español", "info about português")
>
> doc <- newXMLDoc()
> root <- newXMLNode("tips", doc = doc)
> for (i in 1:length(concepts)) {
> cur.concept <- concepts[i]
> cur.info <- info[i]
> cur.tip <- newXMLNode("tip", attrs = c(id = i), parent = root)
> newXMLNode("h1", cur.concept, parent = cur.tip)
> newXMLNode("p", cur.info, parent = cur.tip)
> }
>
> # accented vowels don't come through correctly, but the indents are correct:
> saveXML(doc, file = "test1.xml", indent = T)
>
> Resulting file looks like this:
> <?xml version="1.0"?>
> <tips>
> <tip id="1">
> <h1>español</h1>
> <p>info about español</p>
> </tip>
> <tip id="2">
> <h1>português</h1>
> <p>info about português</p>
> </tip>
> </tips>
>
> # accented vowels are correct, but the indents are no longer correct:
> saveXML(doc, file = "test2.xml", indent = T, encoding = "UTF-8")
>
> Resulting file:
> <?xml version="1.0" encoding="UTF-8"?>
> <tips><tip id="1"><h1>español</h1><p>info about español</p></tip><tip id="2"><h1>português</h1><p>info about português</p></tip></tips>
>
> I tried to workaround the problem by simply loading in that resulting file and saving it again:
> doc2 <- xmlInternalTreeParse(file = "test2.xml", asTree = T)
> saveXML(doc2, file = "test_word_around.xml", indent = T)
>
> but still don't get the indents.
>
> Does setting encoding = "UTF-8" override indents = TRUE in saveXML()?
>
> Thanks. Earl
>
>
>
More information about the R-help
mailing list