Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re^3: XML::LibXML findnodes and namespaces

by roman (Monk)
on Mar 30, 2007 at 11:13 UTC ( #607444=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://607444]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (5)
As of 2022-01-19 16:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:












    Results (55 votes). Check out past polls.

    Notices?