Re: [R] XML - get node by name

2008-09-07 Thread Gabor Grothendieck
On Sun, Sep 7, 2008 at 2:56 PM, Antje <[EMAIL PROTECTED]> wrote: > 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 > understand it. > > Oh, I guess I understand a bit more > > xpathApply(doc, "//val", function(n) xmlValue(n)) or ju

Re: [R] XML - get node by name

2008-09-07 Thread Antje
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 understand it. 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 tha

Re: [R] XML - get node by name

2008-09-07 Thread Gabor Grothendieck
On Sun, Sep 7, 2008 at 12:10 PM, Gabor Grothendieck <[EMAIL PROTECTED]> wrote: > In particular try this: > >> Lines <- ' > + > + > + 22 > + 45 > + > + > + 44 > + 11 > + > + > + ' >> >> library(XML) >> doc <- xmlTreeParse(Lines, asText = TRUE, trim = TRUE, useInternalNo

Re: [R] XML - get node by name

2008-09-07 Thread Duncan Temple Lang
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Hi Antje Well, the XML package gives you a variety of ways to parse an XML document and manipulate it in R. Perhaps the approach that best matches the Java-style you outline is to use XPath to access nodes. To do this, you use doc = xmlTreeParse("fi

Re: [R] XML - get node by name

2008-09-07 Thread Gabor Grothendieck
In particular try this: > Lines <- ' + + + 22 + 45 + + + 44 + 11 + + + ' > > library(XML) > doc <- xmlTreeParse(Lines, asText = TRUE, trim = TRUE, useInternalNodes = > TRUE) > root <- xmlRoot(doc) > > data1 <- getNodeSet(root, "//data")[[1]] > xmlValue(getNodeSet(dat

Re: [R] XML - get node by name

2008-09-07 Thread Dirk Eddelbuettel
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

Re: [R] XML - get node by name

2008-09-07 Thread Ajay ohri
well not sure how its done in R , but heres a way to do it in simple Excel. http://decisionstats.com/2008/parsing-xml-files-easily/ Parsing XML files easily To parse a XML (or KML or PMML) file easily without using any complicated softwares, here is a piece of code that fits right in your excel s

[R] XML - get node by name

2008-09-07 Thread Antje
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