Nokogiri (Ruby): Extract tag contents for a specific attribute inside each node

HarvmomaImachek

New Member
I have a XML with the following structure\[code\]<Root> <Batch name="value"> <Document id="ID1"> <Tags> <Tag id="ID11" name="name11">Contents</Tag> <Tag id="ID12" name="name12">Contents</Tag> </Tags> </Document> <Document id="ID2"> <Tags> <Tag id="ID21" name="name21">Contents</Tag> <Tag id="ID22" name="name22">Contents</Tag> </Tags> </Document> </Batch></Root>\[/code\]I want to extract the contents of specific tags for each Document node, using something like this:\[code\]xml.xpath('//Document/Tags').each do |node| puts xml.xpath('//Root/Batch/Document/Tags/Tag[@id="ID11"]').textend\[/code\]Which is expected to extract the contents of the tag with id = "ID11" for each 2 nodes, but retrieves nothing. Any ideas?
 
Back
Top