[R] XML - get node by name
Gabor Grothendieck
ggrothendieck at gmail.com
Sun Sep 7 18:10:59 CEST 2008
In particular try this:
> Lines <- '
+ <root>
+ <data loc="1">
+ <val i="t1"> 22 </val>
+ <val i="t2"> 45 </val>
+ </data>
+ <data loc="2">
+ <val i="t1"> 44 </val>
+ <val i="t2"> 11 </val>
+ </data>
+ </root>
+ '
>
> library(XML)
> doc <- xmlTreeParse(Lines, asText = TRUE, trim = TRUE, useInternalNodes = TRUE)
> root <- xmlRoot(doc)
>
> data1 <- getNodeSet(root, "//data")[[1]]
> xmlValue(getNodeSet(data1, "//val")[[1]])
[1] " 22 "
>
On Sun, Sep 7, 2008 at 11:42 AM, Dirk Eddelbuettel <edd at debian.org> wrote:
>
> On 7 September 2008 at 10:22, Antje wrote:
> | I try to rewrite some Java-code with R. It deals with reading XML files. I
> [...]
> | Now, I'd like to do something like this in R. Most important would be to
> | retrieve a node just by its name, not by the whole path. How is it possible?
> |
> | Can anybody help me with this issue?
>
> Have you looked at the "XML" package for R ?
>
> Dirk
>
> --
> Three out of two people have difficulties with fractions.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
More information about the R-help
mailing list