Note that there are some explanatory texts on larger screens.

plurals
  1. POperl, libxml, xpath : how to get an element through an attribute in this example .xml file
    primarykey
    data
    text
    <p>I would like your help in the following :</p> <p>given the .xml file :</p> <pre><code>&lt;network&gt; &lt;netelement&gt; &lt;node pwd="KOR-ASBG" func="describe_SBG_TGC"&gt; &lt;collection category="IMT" dir="Stream_statistics"&gt;&lt;/collection&gt; &lt;/node&gt; &lt;/netelement&gt; &lt;netelement&gt; &lt;node pwd="ADR-ASBG" func="describe_SBG_TGC"&gt; &lt;collection category="IMT" dir="Stream_statistics"&gt;&lt;/collection&gt; &lt;collection category="IMT" dir="Proxy_registrar_statistics_ACCESS"&gt;&lt;/collection&gt; &lt;/node&gt; &lt;/netelement&gt;&lt;/network&gt; </code></pre> <p>What I would like to do is to get the element with the attribute "KOR-ASBG", for example, but using only XPath.</p> <p>I have written the following Perl code :</p> <pre><code>#!/usr/bin/perl -w use strict ; use warnings ; use XML::LibXML ; use Data::Dump qw(dump) ; my $dump = "/some_path/_NETELEMENT_.xml" ; my $parser = new XML::LibXML ; my $doc ; eval{ $doc = $parser-&gt;parse_file($dump) ; } ; if( !$doc ) { print "failed to parse $dump" ; next ; } my $root = $doc-&gt;getDocumentElement ; my $_demo = $root-&gt;find('/network/netelement/node[@pwd="KOR-ASBG"]') ; print dump($_demo)."\n" ; </code></pre> <p>But, what it gets dispalyed is :</p> <pre><code>bless([bless(do{\(my $o = 155172440)}, "XML::LibXML::Element")], "XML::LibXML::NodeList") </code></pre> <p>So the question would be, how can I get the XML Element that contains the "pwd" attribute (that equals "KOR-ASBG"), using XPath ?</p> <p>Thank you :)</p> <p>PS. I have also tried :</p> <pre><code>my @_demo = $root-&gt;findnodes('/network/netelement/node[@pwd="KOR-ASBG"]') ; print dump(@_demo)."\n" ; </code></pre> <p>and what it gets displayed is :</p> <pre><code>bless(do{\(my $o = 179552448)}, "XML::LibXML::Element") </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload