Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Your XML has no target namespace. It's not an issue but you have to take it into account.</p> <p>You can specify which parser <code>XML::Simple</code> will use.</p> <p>Here is a code example, with <code>XML::Simple</code> that gets the result you expect.</p> <pre><code>tvnshack$ ./a.pl Trying bugtrack.xml ... bugtrack.xml is indeed valid BugTrackID is: 57982 </code></pre> <p>The code is bellow ... to be adjusted to your liking (it's based on some live code I use in production).</p> <pre><code>#!/opt/perl/bin/perl -w use strict; use XML::Simple qw(:strict); use Data::Dumper; # Supported namespaces my $nspcBUGT = 'urn:alerts.symantec.com'; my $parsingfailed = 0; my $XMLdata; my $XMLfname = 'bugtrack.xml'; print STDOUT "Trying $XMLfname ... "; $XML::Simple::PREFERRED_PARSER = 'XML::SAX::Expat'; my $simpleCstr = XML::Simple-&gt;new( Cache =&gt; [ 'memshare' ], KeyAttr =&gt; [], ForceArray =&gt; 1, KeepRoot =&gt; 1, ContentKey =&gt; 'value', NSExpand =&gt; 1, NormaliseSpace =&gt; 1); eval { $parsingfailed++; # if the parsing fails, the module will terminate the process abruptly. $XMLdata = $simpleCstr-&gt;XMLin($XMLfname); # This line of code will not be executed, leaving $parsingfailed&gt;0. $parsingfailed = 0; }; if ( $parsingfailed &gt; 0) { print STDERR "Error: That XML file &lt;$XMLfname&gt; can not be read, does not exist or is not a valid XML file (possible wrong namespace too).\n"; } else { if (defined($XMLdata-&gt;{"Alerts"})) { print STDOUT "$XMLfname is indeed valid\n"; print STDOUT " BugTrackID is: " . $XMLdata-&gt;{'Alerts'}-&gt;[0]-&gt;{"{$nspcBUGT}AlertDocument"}-&gt;[0]-&gt;{"{$nspcBUGT}BugTraqID"}-&gt;[0] . "\n"; # print Dumper($XMLdata) . "\n"; } } __END__ </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
    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