Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re^3: Finding node with attribute XML::LibXML

by ikegami (Patriarch)
on Sep 30, 2014 at 19:49 UTC ( [id://1102468]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Finding node with attribute XML::LibXML
in thread Finding node with attribute XML::LibXML

If you want to search the whole document, you can use
/descendant::Volume[@VolumeCategory="L"]
which can be abbreviated to
//Volume[@VolumeCategory="L"]

Should I understand that that methods does not support attribute?

If you're asking if getElementsByTagName can filter the returned nodes to retain only those with a specific attribute value, then the answer is no. The only argument it takes is a tag name. You could do

my @matching = grep { my $vc = $_->getAttribute('VolumeCategory'); defined($vc) && $vc eq "L" } $doc->getElementsByTagName('Volume');

but aforementioned

my @matching = $doc->findnodes('//Volume[@VolumeCategory="L"]');

is much simpler.

Replies are listed 'Best First'.
Re^4: Finding node with attribute XML::LibXML
by Jim (Curate) on Oct 01, 2014 at 00:57 UTC

    I think you meant to type…

    /descendant::Volume[@VolumeCategory="L"]

    With just one colon, you get…

    XPath error : Undefined namespace prefix
      Thanks, fixed

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (1)
As of 2024-04-24 16:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found