REXML, XPath and Namespace


#1

Hi.

I want to parse an xml file using REXML::XPath. I can easily navigate
through the xml-tree with methods like ‘XPath.match(xml, “child::*”)’
and. But i can’t
access nodes with the structure ‘prefix:name’. Even this call is not
working (it doesn’t hit any node):

sub_tags = REXML::XPath.match(xml, “/rss/channel/item/dc:date”, {
“dc”=>“http://purl.org/dc/elements/1.1/” })

Do you know what i’am doing wrong?
Thanks

<?xml version="1.0" encoding="UTF-8"?>



Zvents search for events matching within 60 miles of
6
http://www.zvents.com/search?.
60
Zvents search for even Germany
returesults.
<stream_count>2</stream_count>

MIR DETSTWA
International Exhibition of Goods for
Childg



http://www.zvents.com/events/show/896719-MIR-DETSTWA
http://www.zvents.com/events/show/896719-MIR-DETSTWA
dc:creatormBLAST</dc:creator>
896719
<parent_id></parent_id>
<series_count></series_count>
geo:lat50.12</geo:lat>
geo:long8.68</geo:long>
Wed, 30 May 2007 07:11:46 +0000
dc:date2007-05-30T07:11:46+0000</dc:date>
xCal:dtstart2007-10-03 00:00:00 +0000</xCal:dtstart>
xCal:dtend2007-10-07 00:00:00 +0000</xCal:dtend>


#2

On 6/16/07, hinsen removed_email_address@domain.invalid wrote:

Even this call is not
working (it doesn’t hit any node):

This seemed to work for me:
require ‘rexml/document’
=> true

INPUT = <<INPUT_XML


Zvents search for events matching within 60 miles of
6

Wed, 30 May 2007 07:11:46 +0000
dc:date2007-05-30T07:11:46+0000</dc:date>



INPUT_XML
=> “<rss xmlns:geo=“http://www.w3.org/2003/01/geo/wgs84_pos#
version=“2.0”\nxmlns:dc=“http://purl.org/dc/elements/1.1/"\nxmlns:xCal="urn:ietf:params:xml:ns:xcal”>\n
\n Zvents search for events matching within 60
miles of 6\n \n Wed, 30 May 2007
07:11:46 +0000\n
dc:date2007-05-30T07:11:46+0000</dc:date>\n \n
\n \n”

xml = REXML::Document.new(INPUT)
=> … </>

a = REXML::XPath.match(xml, “/rss/channel/item/dc:date”, {
“dc”=>“http://purl.org/dc/elements/1.1/” })
=> [dc:date … </>]

a.to_s
=> “dc:date2007-05-30T07:11:46+0000</dc:date>”