badpopcorn

libxml default namespace

Written by Moe on August 25, 2007 | 1 Comment

Can’t find your nodes? Neither could we. So it turns out that Xpath doesn’t behave well with default namespaces. This is what Corey and I figured out…hope it helps.

Example XML

<Response xmlns=”http://www.badpopcorn.com/solutions”>

<solutions>

<solution>Don’t got any</solution>

<solutions>

</Response>

Although you can load it into a document, you can’t find any nodes without a little hack (using the word little loosely). Ruby example.

    doc = XML:Document.file(‘http://badpopcorn.com/file.xml’)

    dn = ‘dn: http://www.badpopcorn.com/solutions’

    doc.find(‘//dn:solutions’,dn).each do |node|

        r = node.find(“dn:solution,dn).first.content

Yea, we know how you feel. Way to go Corey.


1 Comment

  1. It HELPED! Definitely….I’d been wrestling with this for a while….had given up on it a few times. Upon revisiting a project, I gave it one more try and found your blog entry. Voilà! it works!

    Thanks

    Comment by Marlon — February 26, 2009 @ 8:25 am

RSS feed for comments on this post.

Sorry, the comment form is closed at this time.