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?