Coercing SVG to W3C Profile
Jaques Distler: Using that local copy of the W3C Validator means we need to adhere to the rather lame restrictions of the XHTML+MathML+SVG DTD
Perhaps this might help.
Notes:
- This code eats unknown namespace declarations. In most cases, this should be caught downstream. If this is a concern, a
die if...
statement or two might be in order. - Non-namespace-well-formed input (as well as any input that causes the parser to
die
) will be returned unmodified. Again, presumably such input will fail validation anyway. Unfortunately, this also precludes the fixing up of comments that contain references to XHTML entity definitions other than the ones predefined by XML itself. Could perhaps be addressed by optionally prefixing the input with a<!DOCTYPE>
for parsing purposes. - In rare cases, this code may unnecessarily declare a harmless
xlink
namespace into the output. - Empty elements will be converted to separate open and close tags. Come to think of it, that might be handy.
- You may want to handle other events, like Comment.