[R] getNodeSet - what am I doing wrong?

Duncan Temple Lang duncan at wald.ucdavis.edu
Mon Aug 30 21:52:46 CEST 2010


Hi Johannes

 This is a common issue.  The document has a default XML namespace, e.g.
the root node is defined as

 <unimod xmlns="http://www.unimod.org/xmlns/schema/unimod_tables_1"...>
   .....

 So you need to specify which namespace to match in the XPath expression
in getNodeSet().  The XML package  provides a "convenient" facility for
this. You need only specify the prefix such as "x" and that will
be bound to the default namespace. You need to specify this in
two places - where you use it in the XPath expression and
in the namespaces argument of getNodeSet()

So
   getNodeSet(test, "//x:modifications_row", "x")

gives you probably what you want.

 D.



On 8/30/10 8:02 AM, Johannes Graumann wrote:
> library(XML)
>> test <- xmlTreeParse(
>> "http://www.unimod.org/xml/unimod_tables.xml",useInternalNodes=TRUE)
>> getNodeSet(test,"//modifications_row")



More information about the R-help mailing list