Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

XML::LibXML, svg, default namespace: Why so slow?

by 7stud (Deacon)
on Jan 03, 2015 at 22:01 UTC ( [id://1112075]=perlquestion: print w/replies, xml ) Need Help??

7stud has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks,

libxml is supposed to be fast, but I am trying to alter a small XML file, and XML::LibXML is intolerably slow:
use strict; use warnings; use 5.016; use XML::LibXML; my $dom = XML::LibXML->load_xml(string => <<'END_OF_XML'); <?xml version="1.0" encoding="UTF-8" standalone="no" ?> <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Grap +hics/SVG/1.1/DTD/svg11.dtd"> <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1"> <tag> <text> <tspan>Hello</tspan> </text> </tag> </svg> END_OF_XML #Deal with the namespace declared in the svg tag: my $xpc = XML::LibXML::XPathContext->new($dom); $xpc->registerNs('ns', 'http://www.w3.org/2000/svg'); my ($tspan) = $xpc->findnodes('//ns:text/ns:tspan'); #Change the tspan's text: $tspan->removeChildNodes(); $tspan->appendTextNode("Goodbye"); #Prove that the tspan's text changed: say $tspan; say $dom->toString;

Am I doing something wrong?

Replies are listed 'Best First'.
Re: XML::LibXML, svg, default namespace: Why so slow?
by choroba (Cardinal) on Jan 03, 2015 at 22:10 UTC
    When I ran your script, it seemed tolerably fast (0.056s).

    But, when I removed the DOCTYPE declaration, it got even faster: 0.043s.

    When I put it back but changed the URL to a non-existent one, the script started to crawl at 0.447s.

    So, maybe, check your connection speed?

    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
      Thanks. I wasn't timing my program because it took approximately 5 seconds to run. I thought I tried removing the DOCTYPE to see if that was the problem, but now when I remove it, the results appear instantaneously, so you were right: the problem was my connection.
Re: XML::LibXML, svg, default namespace: Why so slow?
by sundialsvc4 (Abbot) on Jan 04, 2015 at 02:49 UTC

    Hmmm ... when presented with a DOCTYPE (which of course references a URL at w3.org as its means of defining the type), does anything attempt to reach-out to the Internet to retrieve that DTD?   If it did, and failed, a timeout could occur.   I quite-honestly don’t recall ...   But, if it is “noticeably slow,” then it obviously can’t be the job of XML-parsing.   It must be “something else.”   Like this, maybe.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2024-04-20 00:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found