I don't understand why you don't get same namespace every time
Anyway, If the XML are small and you need access to just a few nodes you could you XML::Simple, for example:
use XML::Simple;
use strict;
use warnings;
my $xml = <<XML;
<?xml version="1.0" standalone="yes"?>
<sdnList>
<sdnEntry>
<lastName>Hello world !</lastName>
</sdnEntry>
</sdnList >
XML
my $xml1 = XMLin($xml);2
my $result = $xml1->{sdnEntry}->{lastName};
print "result:$result\n"; ;
$xml = <<XML;
<?xml version="1.0" standalone="yes"?>
<sdnList xmlns="http://tempuri.org/sdnList.xsd" >
<sdnEntry>
<lastName>Hello world !</lastName>
</sdnEntry>
</sdnList >
XML
my $xml2 = XMLin($xml);
$result = $xml1->{sdnEntry}->{lastName};
print "result:$result\n";
I've had performance problems using xpath queries, even it was faster to instantiate the document and consumed less memory than XML::Simple, overall it was slower accessing nodes ( which makes totally sense as XML::Simple returns a hash ).
My point is if you need a simple parser ( i.e: for config files or for consuming small services once a while ) I'd stick to XML::Simple. In environments of high volume or frequent parsing of huge XML documents I would use Expat instead it is really fast.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|