user2722968
user2722968

Reputation: 16495

Validate SVG with custom namespace against DTD

I generate SVGs like the following

<svg xmlns="http://www.w3.org/2000/svg" xmlns:foobar="http://foobar.com">
<path d="..." foobar:foo="bar"/>
</svg>

Without the custom attribute foo(and the namespace foobar), the entire SVG validates against the DTD. Clearly, I'm using the custom namespace wrong, as adding the foobar namespace and associated attributes causes xmllintto fail validation, starting with the declaration of xmlns:foobar=..., which itself is not an element of svg. Is my declaration wrong? Is it even possible to validate against the DTD when using custom namespaces/attributes?

Upvotes: 5

Views: 445

Answers (1)

imhotap
imhotap

Reputation: 2490

Assuming you're validating against the SVG 1.1 2nd ed. DTD at its official URL shown below, you could make use of the extensive customization features of the SVG DTD by re-defining ("preempting") the default empty string value for the SVG.External.attrib parameter entity such that it contains attribute list declaration fragments for your custom attributes (plus the xmlns:foobar declaration):

<!DOCTYPE svg
  SYSTEM "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd" [
  <!ENTITY % SVG.External.attrib
    "xmlns:foobar CDATA #IMPLIED
     foobar:foo CDATA #IMPLIED">
]>
<svg xmlns="http://www.w3.org/2000/svg"
     xmlns:foobar="http://foobar.com">
  <path d="M 0 0 z" foobar:foo="bar"/>
</svg>

The SVG DTD ultimately expands the replacement text for SVG.External.attrib in individual declarations for SVG elements. There might be more appropriate parameter entities to customize/overwrite depending on your purpose, such as SVG.Core.extra.attrib.

Note the document, when run through xmllint --valid --loaddtd, produces unrelated warnings on my Ubuntu machine where an SVG DTD is cached locally, as evidenced by xmllint's quick response compared to fetching the DTD via http (which results in other warnings for me).

Upvotes: 2

Related Questions