I must be missing something incredibly obvious and I have finally given up trying to figure out what is wrong. I'm trying to search a simple piece of XML to find all of the <Parent>
nodes. I'm using R 3.2.2 and the XML package. Here's the code with the example XML:
library(XML)
example_xml <- paste(
'<?xml version="1.0"?>',
'<GetProductCategoriesForASINResponse xmlns="http://mws.amazonservices.com/schema/Products/2011-10-01">',
'<GetProductCategoriesForASINResult>',
'<Self>',
'<ProductCategoryId>11056341</ProductCategoryId>',
'<ProductCategoryName>Chicken</ProductCategoryName>',
'<Parent>',
'<ProductCategoryId>11056281</ProductCategoryId>',
'<ProductCategoryName>Dog</ProductCategoryName>',
'<Parent>',
'<ProductCategoryId>11055991</ProductCategoryId>',
'<ProductCategoryName>Monkey</ProductCategoryName>',
'<Parent>',
'<ProductCategoryId>11055981</ProductCategoryId>',
'<ProductCategoryName>Frog</ProductCategoryName>',
'<Parent>',
'<ProductCategoryId>3760911</ProductCategoryId>',
'<ProductCategoryName>Iguana</ProductCategoryName>',
'</Parent>',
'</Parent>',
'</Parent>',
'</Parent>',
'</Self>',
'</GetProductCategoriesForASINResult>',
'<ResponseMetadata>',
'<RequestId>abs123</RequestId>',
'</ResponseMetadata>',
'</GetProductCategoriesForASINResponse>',
sep = ''
)
categories_xml <- xmlTreeParse(example_xml, useInternalNodes = TRUE)
root <- xmlRoot(categories_xml)
category_nodes <- getNodeSet(root, '//Parent')
I would expect category_nodes
to contain 4 nodes but instead it is returning 0.