in reply to how to get XML::LibXML perfect xpath query ?

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.

Replies are listed 'Best First'.
Re^2: how to get XML::LibXML perfect xpath query ?
by ikegami (Patriarch) on Jun 13, 2010 at 00:07 UTC

    In environments of high volume or frequent parsing of huge XML documents I would use Expat instead it is really fast.

    In my experience, XML::LibXML is 12x faster than XML::Parser (Expat) at creating the same Perl-land data structure.

      My DOM parser tests compared XML::Simple vs. XML::LibXML in two platforms Solaris 10 and Linux 2.6, all my tests in Solaris ( different documents with different sizes ) showed XML::LibXML was slower than XML::Simple ( It was much slower accessing nodes), as for Linux it was the opposite and XML::LibXML was 8-10x faster than XML::Simple.

      On the other hand comparing a SAX parser using XML::Parser vs. a DOM parser using XML::LibXML or XML::Simple, expat won in both Solaris and Linux.

      Honestly, I haven't tried XML::LibXML::SAX and maybe it is way faster than XML::Parser.

      This link its a bit outdated but It has some benchmarks. Probably things changed notably since then.

        It was much slower accessing nodes

        You seem to have missed "at creating the same Perl-land data structure." Visiting every node was included in the benchmark.

        A task using SOAP::Lite that took two minute was sped up to 15 seconds when I replaced Expat with XML::LibXML as its parser. I kept the change mininal: XML::LibXML was used to create the same data structure that Expat was used to create.

        Honestly, I haven't tried XML::LibXML::SAX and maybe it is way faster than XML::Parser.

        As I mentioned, XML::Parser is by far the fastest existing backend for XML::Simple. I'm pretty sure I've posted benchmarks on PerlMonks.

Re^2: how to get XML::LibXML perfect xpath query ?
by Kanishka.black0 (Scribe) on Jun 13, 2010 at 04:19 UTC
    Definately LibXML can handle complex data structures ... and perfomance is done well ... more over LibXML is well maintained .. unlike other's