Category talk:KanjiVG stroke order images
Invalid XML in various KanjiVG files, missing XML namespace declaration for the "kvg:" prefix, causing broken rendering
[edit]@Spinster: Various files imported from the KanjiVG project no longer display now correctly, in the Wikimedia SVG-to-PNG thumbnail generator, or when viewed directly with conforming XVG viewers and HTML browers. This is not a bug of the SVG-to-PNG thumbnail generator, but bugs in these SVG files, which cannot be viewed (Commons signals a "technical problem loading these files", without more explaination of the cause).
In fact there's a missing (but required) XML namespace declaration for the "kvg:" prefix used to describe each component paths and the SVG group containing them, which should be bound to the URI of the KanjiVG project (I posted already a bug report in this project on GitHub).
Adding this XML declaration ( xmlns:kvg="http://kanjivg.tagaini.net"
in the "svg" element) fixes the problem and this MUST be done now. Before that, these files were rendering in Commons, whose SVG-to-PNG generator used a lenient XML parser, just ignoring unknown non-standard SVG attributes. See an example in https://commons.wikimedia.org/w/index.php?title=File:%E6%95%B0_-_U%2B06570_-_KanjiVG_stroke_order.svg&diff=prev&oldid=882848934 (the diff shows no difference in the description page, the fix is in the SVG content itself, for the newly uploaded file with this fix).
Additionally, these files use the "kvg:" prefix in the value of id="" attributes. This is not critical because this does not invalidate the XML parsing, but this is a violation of the SVG schema (where the colon ":" character is forbidden in valid identifiers, complicating the references for example in CSS styles). For now, the SVG-to-PNG generator uses lenient rules for these non-conforming IDs (which are not needed for the rendering as they are not referenced inside these files, but could become a problem if these files are used within CSS style rules). These ":" colons in IDs should be replaced by hyphens. verdy_p (talk) 06:00, 11 June 2024 (UTC)
- See this GitHub bug report: https://github.com/KanjiVG/kanjivg/issues/451 ... verdy_p (talk) 17:45, 11 June 2024 (UTC)
Note that I have started to update some of these broken files (adding the missing xmlns:kvg="http://kanjivg.tagaini.net"
declaration in the root "svg" element, and fixing id attribute values by replacing the colon by an an hyphen). In all these cases, the edit comment is clear, and fixes the rendering problem.
- Note that some existing pre-rendered thumbnails may be present in cache and does not cause apparent issue when navigating this category, however it is visible each time the SVG is rendered at different image sizes (e.g. when present in "Wikidata Infobox" for stroke order images, or rendered in Wikidata itself, or when viewing images in the history or clicking the image to display it at full size).
My very simple fix solves all these problems because these images are NOT valid SVG without these fixes and Wikimedia servers can no longer render them without the required xmlns:kvg declaration (Spinster incorrectly edited the images with its version of the "Pattypan" image uploading bot which may have bug, or its is caused by its own editing and absence of validation).
- Unlike what Spinster did, I did not remove any "kvg:*" attribute, and did not remove the embedded comment showing attributions and originating from KanjiVG itself.
But KanjiVG apparently does not care about this compatibility problem, or does not want to fix it on their source project: the original images use an embedded DTD with many SLGM declarations, that Wikimedia servers cannot process with its XML loader (for security reason). Such embedded DTD must be removed on Commons, however the "xmlns:kvg" declaration must remain if we preserve the custom kvg:*="..." attributes (privately used by KanjiVG) to describe the composition, and CANNOT be automatically implied by "!ATTLIST" and "!ATTRIBUTE" DTD declarations for "g" elements, as they were with the embedded DTD that Wikimedia does not support (embedded DTD is a very old XML 1.0 feature, deprecated since long, and causing problems now, even with the W3C validator, and forbidden in "svg" elements integrated by HTML5 itself!); the only safe way is to add the xmlns declaration explicitly, and just once on the root "svg" element (and not for each "g" sub-element as it was initially incorrectly designed in KanjiVG). The other way would be to drop all custom kvg:*="" attributes (which are not part of SVG itself and in fact cannot be validated by the W3C validator: these custom attributes are specific to internal KanjiVG project management, meant for documentation only for advanced contributors to KanjiVG project itself, and never used by any standard SVG processors). verdy_p (talk) 11:46, 19 June 2024 (UTC)