SVG with custom namespace fails check
Checking a SVG using a custom namespace fails with an error--epubcheck doesn't seem to recognize the custom namespace. Here's a minimal, valid test SVG:
<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:test="https://example.org" version="1.1" viewBox="0 0 10 10" test:foo="bar">
</svg>
Expected result: The valid SVG should not generate check errors.
Actual result: Error while parsing file 'attribute "test:foo" not allowed here; expected attribute "alignment-baseline", "baseProfile", "baseline-shift", "class", "clip", "clip-path", "clip-rule", "color", "color-interpolation", "color-interpolation-filters", "color-profile", "color-rendering", "contentScriptType", "contentStyleType", "cursor", "direction", "display", "dominant-baseline", "enable-background", "externalResourcesRequired", "fill", "fill-opacity", "fill-rule", "filter", "flood-color", "flood-opacity", "font-family", "font-size", "font-size-adjust", "font-stretch", "font-style", "font-variant", "font-weight", "glyph-orientation-horizontal", "glyph-orientation-vertical", "height", "id", "image-rendering", "kerning", "letter-spacing", "lighting-color", "marker-end", "marker-mid", "marker-start", "mask", "ns:type", "onabort", "onactivate", "onclick", "onerror", "onfocusin", "onfocusout", "onload", "onmousedown", "onmousemove", "onmouseout", "onmouseover", "onmouseup", "onresize", "onscroll", "onunload", "onzoom", "opacity", "overflow", "pointer-events", "preserveAspectRatio", "requiredExtensions", "requiredFeatures", "shape-rendering", "stop-color", "stop-opacity", "stroke", "stroke-dasharray", "stroke-dashoffset", "stroke-linecap", "stroke-linejoin", "stroke-miterlimit", "stroke-opacity", "stroke-width", "style", "systemLanguage", "text-anchor", "text-decoration", "text-rendering", "unicode-bidi", "visibility", "width", "word-spacing", "writing-mode", "x", "xml:base", "xml:lang", "xml:space", "y" or "zoomAndPan" (with xmlns:ns="http://www.idpf.org/2007/ops")'.
This and #489 are causing issues with automated validation. It would be best not to write exceptions to EpubCheck, or sanitize SVG created by third party design tools that add their own namespaces.
@chrisauclair Hi, I'm not sure this is the right place but should I understand that we can use a custom namespace in epub3, but it won't be recognized by epubcheck?
@jacqueslelezard, my understanding is that namespaces should be supported because the specs for EPUB 3.1 and 3.0.1 require versions of SVG that use the same namespace rules as XML.
Do we agree that such foreign attributes should be allowed anywhere in SVG? I can easily provide schema changes for this.
Do we agree that such foreign attributes should be allowed anywhere in SVG? I can easily provide schema changes for this.
Agreed. But probably our spec-guru @mattgarrish can have a second look at this ;-)
Technically it's both foreign elements and attributes that are allowed.[1]
Unlike HTML, which requires extending to be valid, SVG just expects foreign elements/attributes to be ignored by the UA. Further, we don't have a content restriction against either in the Content Docs spec.
[1] https://www.w3.org/TR/SVG/extend.html
If we do not use NVDL, alowing foreign elements requires a lot of changes to RNG schemas. But if we use NVDL, it is very easy to allow foreign elements and attributes without changing RNG schemas. Does epubcheck now use NVDL?
There seems to be a SVG NVDL file in src/main/resources/com/adobe/epubcheck/schema/30/, but I think it's only used for the tests. Maybe I'm wrong and @rdeltour can help.
However, the SVG validation seems to be based on the RNC file in the same folder, which is referenced in the Java sources.
Don't know if this helps...
With nvdl you can remove the foreign attributes and elements from validation prior to comparing against the rnc schema. Without it, validation get more complicated as @murata0204 says.
But this is a little more complicated problem. I was digging through the specs, and even though SVG is permissive, HTML is not. So when an SVG is embedded in HTML, foreign namespaces are not allowed, as HTML only recognizes HTML, SVG and MathML for content. Only a top-level SVG document would allow foreign namespaces.
So the current behaviour is correct when validating within HTML, and would need to be retained in that context.
If NVDL validation is now invoked by epubcheck internally, I think that an NVDL script (only for SVG cont. doc) is a good solution. It can allow both foreign elements and attributes. If not, I am inclined to allow foreign attributes by revising the RNG schema for SVG.
It appears that NVDL is used for EPUB2 validation but not for EPUB3 validation. See \src\main\java\com\adobe\epubcheck\ops\OPSChecker.java and \src\main\java\com\adobe\epubcheck\xml\XMLValidators.java.
I think that the best approach is to use NVDL for EPUB 3 validation. But regression test, is probably required for such a big change. I am afraid that I cannot do the test. Can somebody help me?
Matt wrote:
But this is a little more complicated problem. I was digging through the specs, and even though SVG is permissive, HTML is not.
So, we need a different NVDL script for SVG cont docs and XHTML cont docs.
Let's revisit this in the next/4.2.0 branch where all the EPUB 3.x schemas have been updated.
I briefly looked into this. As the extensibility rules vary for embedded SVG islands and top-level SVG documents, I would suggest:
- leave the XHTML validation as-is, i.e. relying on the validator.nu schemas (and ultimately, on the full validator.nu code)
- use NVDL for SVG Content Documents
I can already tweak the XML parser to support data-* attributes in SVG (both contexts), and remove attributes in foreign namespaces in an XHTML context (in an SVG context, this would be handled by NVDL).
I can probably create an NVDL script for this purpose.
@murata2makoto I've made a start in PR #970. Feel free to improve on it.
Closed in #970