On 01.11.2012 06:29, Manish Gupta wrote:> HI,
>
> I need to parse an xml where key name are same but values are different.
>
> <root>
> <test>
> Some dummy text
> </test>
> <node id="1">one</node>
> <node id="2">two</node>
> <node id="3">three</node>
> </root>
>
> When i use xmlGetAttr() function i always get one as value. How can i get
> one , two and three? Pls help me out of this pblm .
Hi!
I would start by looking at "A Short Introduction to the XML package for
R". The xPath part of the document seems relevant to your problem.
http://www.omegahat.org/RSXML/shortIntro.html
I'm not exactly sure of what you are trying to do, but here's a start:
foo <- xmlInternalTreeParse("yourfile.xml")
nodes <- getNodeSet(foo, "//node[@id]")
sapply(nodes, xmlGetAttr, "id")
sapply(nodes, xmlValue)
--
Mikko Korpela
Aalto University School of Science
Department of Information and Computer Science