[R] Need help extracting info from XML file using XML package
Wacek Kusnierczyk
Waclaw.Marcin.Kusnierczyk at idi.ntnu.no
Mon Mar 2 18:07:52 CET 2009
Duncan Temple Lang wrote:
>
>> not really: the xpath pattern '//coordinates' does say 'find all
>> coordinates nodes searching from the root', but the root here is not the
>> original root of the whole document, but each polygon node in turn.
>> try:
>>
>> root = xmlInternalTreeParse('
>> <root>
>> <foo>
>> <bar>1</bar>
>> </foo>
>> <foo>
>> <bar>2</bar>
>> </foo>
>> </root>')
>>
>> xpathApply(root, '//foo', xpathSApply, '//bar', xmlValue)
>> # equals list("1", "2"), not list(c("1", "2"), c("1", "2"))
>>
>
> Just for the record and to avoid confusion for anyone reading the
> archives in the future, the behaviour displayed above is from an old
> version of the XML package (mid 2008). Subsequent versions yield
> the second result as the //bar works from the root of the document.
> But using .//bar would search from the foo down the sub-tree.
>
> The reason for this is that, having used XPath to get a node, e.g.
> foo, we often want to go back up the XML tree from that current node,
> e.g.
> ../
> ./ancestor::foo
> and so on.
just for the record: this is an excellent example of where the
behaviour (implementation + interface) of a package changes to make it
better, despite the trillions of lines of old code that get broken by
the change. thanks, duncan.
vQ
More information about the R-help
mailing list