Hi,
I have one xml file.
<Class>
<Node1 code ="1"> First node </Node1>
<Node2 code ="1"> Second node </Node2>
<Node3 code ="1"> Third node </Node3>
<Node1 code ="2"> Fourth node </Node1>
</Class>
for (i in 1:xmlSize())
{
print(Class[i]) # how can i filter Node1 ?
}
by using xmlChildren(Class), i get nodes of Class. How can i filter Node1
and print other elements of Class node?
Regards
--
View this message in context: http://r.789695.n4.nabble.com/How-to-filter-xml-value-in-R-tp4649465.html
Sent from the R help mailing list archive at Nabble.com.
How to filter xml value in R?
3 messages · Manish Gupta, Ben Tupper
Hi,
On Nov 13, 2012, at 11:55 PM, Manish Gupta wrote:
Hi,
I have one xml file.
<Class>
<Node1 code ="1"> First node </Node1>
<Node2 code ="1"> Second node </Node2>
<Node3 code ="1"> Third node </Node3>
<Node1 code ="2"> Fourth node </Node1>
</Class>
for (i in 1:xmlSize())
{
print(Class[i]) # how can i filter Node1 ?
}
by using xmlChildren(Class), i get nodes of Class. How can i filter Node1
and print other elements of Class node?
I think the XML functions "[" and "[[" are what you are looking for. These operate like the xmlChildren function does. You needn't loop through looking for the match - instead, just subscript by the node name. txt <- "<Class> <Node1 code =\"1\"> First node </Node1> <Node2 code =\"1\"> Second node </Node2> <Node3 code =\"1\"> Third node </Node3> <Node1 code =\"2\"> Fourth node </Node1> </Class>" node0 <- xmlRoot( xmlTreeParse(txt, useInternalNodes = TRUE) ) node1 <- node0[["Node1"]]
Thanks! It works -- View this message in context: http://r.789695.n4.nabble.com/How-to-filter-xml-value-in-R-tp4649465p4649488.html Sent from the R help mailing list archive at Nabble.com.