Forums | Admin

Discussion Forums: help

Start New Thread Start New Thread
Message: 91206
BY: Adhamh Findlay (adhamh)
DATE: 2009-10-24 21:09
SUBJECT: RE: using xpath to find sub nodes

 

Thanks Sid,

This is contrived but illustrates the problem:

<code>
def test_test_xml()
xml_ns = 'Document:http://www.google.com/books/'

xml_document = XML::Document.file('./test_pages/test.xml')
book_xpath = '//Document:View/Document:Books'
book_title_xpath = '//Document:Title'

xml_document.find(book_xpath, xml_ns).each() { | item |
puts item
item.find(book_title_xpath, xml_ns).each() { |item2|
puts '========================'
puts 'name: ' + item2.content().strip()
}
}
end
</code>

Here is the XML:

<code>

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<Document xmlns="http://www.google.com/books/";>
<View>
<Books>
<Title>pragmatic programming</Title>
</Books>

<Comics>
<Title>x-men</Title>
</Comics>
</View>
</Document>

</code>

Thanks,

Adhamh


Thread View

Thread Author Date
using xpath to find sub nodesAdhamh Findlay2009-10-24 17:57
      RE: using xpath to find sub nodesdreamcat four2009-10-24 18:20
            RE: using xpath to find sub nodesAdhamh Findlay2009-10-24 20:27
      RE: using xpath to find sub nodesSid Eaton2009-10-24 20:39
            RE: using xpath to find sub nodesAdhamh Findlay2009-10-24 21:09
                  RE: using xpath to find sub nodesSid Eaton2009-10-25 15:17
                        RE: using xpath to find sub nodesAdhamh Findlay2009-10-25 17:38
                              RE: using xpath to find sub nodesSid Eaton2009-10-25 21:47
                                    RE: using xpath to find sub nodesAdhamh Findlay2009-10-25 22:03

Post a followup to this message