Skip Menu |

This queue is for tickets about the SVG CPAN distribution.

Report information
The Basics
Id: 58153
Status: open
Priority: 0/
Queue: SVG

People
Owner: Nobody in particular
Requestors: LGEHLEN [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 2.50
Fixed in: (no value)



Subject: CDATA are no child nodes
Dear Ronan, I have noticed that SVG does not treat PCDATA sections (e.g. inside a text elements) as child nodes. This leads to several problems. 1) According to the DOM (e.g. http://www.w3.org/TR/DOM-Level-3- you do for example my $svg = SVG->new(width => 200, height => 200); my $text = $svg->text('x' => 20, 'y' => 100, id => 't01'); $text->tspan->cdata('foo'); $text->cdata('bar'); then $text->getChildNodes should give you the tspan and the cdata nodes. XML parsers like libxml2 do this. If you feed the SVG document <?xml version="1.0" standalone="no"?> <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> <svg width="200" height="200" xmlns="http://www.w3.org/2000/svg" version="1.1"> <text x="20" y="100"><tspan>foo</tspan>bar<tspan>baz</text> </svg> into the code use XML::LibXML; my $parser = XML::LibXML->new(); $parser->validation(0); $parser->no_network(1); $parser->recover(1); my $dom = $parser->parse_file('tspan_cdata.svg'); foreach($dom->getElementsByTagName('text')) { foreach($_->getChildNodes) { print $_->getName, "\n"; } } you get the output tspan #text I am aware of the fact that SVG does not attempt to implement the full DOM, but I think that the supported subset should follow the DOM specification. 2) More importantly, the issue is not purely academic. The SVG DTD (see http://www.w3.org/TR/SVG11/text.html#TextElement for the relevant section) specifies the content of the text element as: "( #PCDATA | %SVG.Description.class; | %SVG.Animation.class; %SVG.TextContent.class; %SVG.Hyperlink.class; %SVG.text.extra.content; )*" This means that it is perfectly valid to mix multiple tspan (or tref etc.) elements with multiple CDATA sections. However, the code my $svg = SVG->new(width => 200, height => 200); my $text = $svg->text('x' => 20, 'y' => 100, id => 't01'); $text->tspan->cdata('foo'); $text->cdata('bar'); $text->tspan->cdata('baz'); $text->cdata('qux'); print $svg->xmlify, "\n"; produces <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd"> <svg height="200" width="200" xmlns="http://www.w3.org/2000/svg" xmlns:svg="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> <text id="t01" x="20" y="100"> <tspan >foo</tspan> <tspan >baz</tspan>qux</text> <!-- Generated using the Perl SVG Module V2.50 by Ronan Oger Info: http://www.roitsystems.com/ --> </svg> which contains only the second CDATA section. Moreover, the CDATA section always shows up at the very end of the text element, no matter if it was specified before or after tspan elements. Also, the order is not recoverable by inspecting $text->getChildNodes and $text->cdata. However, there are situation where the order does matter. This issue could be resolved by maintaining CDATA sections as child nodes. Best wishes, Lutz
An addition: The proper solution to the problem would probably be to create a SVG::Node class which SVG::Element inherits from. Then a node object would maintain a list of child nodes. To conform with the DOM specification, attributes would also be SVG::Node objects in this list. The getAttributes and a getChildElements methods would then grep the respective nodes from the list. In order to provide backwards compatibility you code add a flag that by default retains the old functionality, but could be switched to the DOM conforming behaviour. I admit that this solution would require some work. However, the muliplicity and order of cdata sections are not only a spec compliance issues. Anyway, I would appreciate a comment from your side whether you are planning to do anything about it or if I have to find a permanent instead of a temporary workaround for the problem. Cheers, Lutz
Hi Lutz, Thanks for the bug reports. I'm speaking for Ronan here, but as far as I know, he is not available for quite some time. There is not much I can do really because I do not fully understand the ins and outs of this issue. If you can you provide a patch for this, this would probably help having a fix released sooner.
Hi Florent, thanks for your reply. I will take a deeper look into the code and try to come up with a patch. I'll have to think about the best way to fix the problem while keeping the current behaviour as default. Best wishes, Lutz
Please fork the repository here: https://github.com/szabgab/SVG and send a test case and if possible a patch too.