b a d p o p c o r n

libxml default namespace

Written by Moe on August 25, 2007 |

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.

Posted in Life Stuff


No Comments »

No comments yet.

RSS feed for comments on this post. | TrackBack URI

Leave a comment

XHTML ( You can use these tags): <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> .