http://qs321.pair.com?node_id=607444


in reply to Re^2: XML::LibXML findnodes and namespaces
in thread XML::LibXML findnodes and namespaces

I think without modification to your XPath, the task is not only difficult, but impossible. I don't see any possibility how plain fooResponse in your XPath expression could match with namespace qualified fooResponse element in your document.

If you want to use XPath and match names regardless namespaces, the name() test is the only solution I can find. The original XPath expressions can be turned to name() variant programmatically (below is my first try).

sub name_matching_xpath { my ($xpath) = @_; return join '/', map { /^([a-z0-9:-]+)(.*)$/i ? "*[name() = '$1']$2" : $_; } sp +lit '/', $xpath; }

Replies are listed 'Best First'.
Re^4: XML::LibXML findnodes and namespaces
by shamu (Acolyte) on Mar 30, 2007 at 21:00 UTC

    Thanks for your help roman. I resorted to a similar solution of replacing my prefixed elements like so...

    $search_path =~ s#([^/:]*:[^/]*)#*[name() = "$1"]#g;

    I've solved my default namespace issue by just doing a namespace lookup and creating an associated prefix. Not exactly the solution I was hoping for, but it works.