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 | |
by 7stud (Deacon) on Jan 04, 2015 at 00:00 UTC | |
|
Re: XML::LibXML, svg, default namespace: Why so slow?
by locked_user sundialsvc4 (Abbot) on Jan 04, 2015 at 02:49 UTC |