Skip to content

XML write?

5 messages · Alberto Monteiro, Gabor Grothendieck, Jeffrey Horner

#
Is there any function to write a XML structure, after it was
read using xmlTreeParse?

Ex: 
library(XML)
x <- xmlTreeParse("Irpf2008/aplicacao/dados/12345678901/12345678901.xml")
# write it...

Alberto Monteiro

PS: please, brazilians, don't be offended by my foul language!
#
By write, do you mean print?

In that case using the basic.xml file that comes with the XML package:

library(XML)
basic.xml <- system.file("exampleData", "basic.xml", package = "XML")

# try this

con <- xmlTreeParse(basic.xml)
root <- xmlRoot(con)
root

# or if you are using internal nodes:

con <- xmlTreeParse(basic.xml, useInternalNodes = TRUE)
root <- xmlRoot(con)
cat(saveXML(root), "\n")

On Tue, Apr 29, 2008 at 9:37 AM, Alberto Monteiro
<albmont at centroin.com.br> wrote:
#
Alberto Monteiro wrote on 04/29/2008 08:37 AM:
Calling:

library(help=XML) # or
help(package=XML)

lists all the functions from the XML package, and saveXML seems to be 
what you want.

I remember having difficulty finding these functions (for listing 
package contents) when I first learned R, and perusing the posting guide 
did mention them in relation to properly posting info about surprising 
behavior and bugs. Maybe a new list item can be added under "Do your 
homework before posting", something like:

* Do help(package="packageName") for a description and function list of 
the installed "packageName", or read the package reference manual from 
CRAN (http://cran.r-project.org/web/packages/).

Best,

Jeff

  
    
  
#
Gabor Grothendieck wrote:
No, I mean "save to a file".

I solved the problem with this:

library(XML)
x <- xmlTreeParse("Irpf2008/aplicacao/dados/12345678901/12345678901.xml")
sink("ihatetheirs.xls")
print(x)
sink()

and then I can edit the saved file to cut some extra information
not-xml related (and do what I want - again, sorry for the foul
language).

Alberto Monteiro
#
On Tue, Apr 29, 2008 at 10:20 AM, Alberto Monteiro
<albmont at centroin.com.br> wrote:
Try saveXML:

con <- xmlTreeParse(basic.xml)
root <- xmlRoot(con)
saveXML(root, "myfile.xml")