Re: [Rd] XML parsing under R / Extracting nodes’ values

From: Hin-Tak Leung <hin-tak.leung_at_cimr.cam.ac.uk>
Date: Tue, 15 May 2007 13:36:31 +0100

That said, you need something like this:

root.node <- xmlTreeParse(x, useInternalNodes = TRUE) nbrelation.set <- getNodeSet(root.node, "//nbRelations") nbrelation.list <- sapply(nbrelation.set, function(x) { xmlValue(x) } )

and nbrelation.list now contains the "2" in nbRelations as text - you may want to do as.numeric() on it as well.

Abdelhakim z wrote:
> Hi,
> I have an XML file which contains among other nodes :
>
> ===myXMLfile.xml===
> (…)
> <nbRelations>2</nbRelations>
> <nbActors>2</nbActors>
> (...)
> <nbRuns>5</nbRuns>
> <nbStep>2000</nbStep>
> (…)
> ===End file===
> I need to extract those values and to make them R variables such as:
> nbRelations = 2
> nbActors = 2
>
> nbRuns = 5
> nbSteps = 2000
>
> I read the help and have seen the examples of the xml package, it
> seems that I need to use xmlTreeParse() function but I don't know how
> exactly as I'm not an R advanced programmer, please can anyone show me
> how to do that explicitly ?
>
> Any help would be much appreciated
>
> Thanks,
>
> Abdel
> University of Boumerdčs
> Algeria
>
> ______________________________________________
> R-devel_at_r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel



R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Tue 15 May 2007 - 12:39:15 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 15 May 2007 - 15:33:23 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.