[R] XML - get node by name
niederlein-rstat at yahoo.de
Sun Sep 7 20:56:57 CEST 2008
Thanks a lot to Gabor and Duncan!
I didn't know that XPath is a standard. I'll give it a deeper look to better
Oh, I guess I understand a bit more
xpathApply(doc, "//val", function(n) xmlValue(n))
would search globally for all nodes named "val" and return its values :-)
So that's excactly what I was looking for. Not caring about the exact location
of a node.
I think, in my case it should be okay, to parse for nodes just by their names.
@ Ajay: Sorry, but I was looking for a solution with R
@ Dirk: I already used the XML package but didn't know the possibilities to
access data as I was used to.
> Hi there,
> I try to rewrite some Java-code with R. It deals with reading XML files.
> I started with the XML package. In Java, I had a very useful method
> which gave me a node by using:
> name of the node
> index of appearance
> start point: global (false) / local (true)
> So, I could do something like this.
> setCurrentChildNode("data", 0);
> --> gives 45
> setCurrentChildNode("data", 1);
> --> gives 11
> --> gives 45
> <data loc="1">
> <val i="t1"> 22 </val>
> <val i="t2"> 45 </val>
> <data loc="2">
> <val i="t1"> 44 </val>
> <val i="t2"> 11 </val>
> 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
> Can anybody help me with this issue?
> R-help at r-project.org mailing list
> PLEASE do read the posting guide
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help