What you need to know about SVG images

12 Jul 2012

I had to processed SVG images as XML documents, and I found several gotcha’s when dealing with them.

First it is better not to include a DOCTYPE declaration in your SVG documents. Otherwise Xerces C++ will throw errors about it.

Secondly, SVG is a namespaced XML dialect. As a consequence, all the XML dialects used in your SVG documents must be bound to their namespaces, otherwise DTDs validation will fail.

Thirdly, make sure you get the units right. pt and px are different. Some units can be omitted others cannot. Read this for more details of how to use units in SVG documents correctly.


CDATA section can be used to escape some characters, like <, > or &, that are forbidden in XML elements. CDATA means character data, which indicates only characters data is within the section to XML parser, and will be ignored by XML parser. That is why CDATA is often used to enclose scripts, like Javascript, in XML or XHTML documents.

“Style” information can also be embedded within a XML/SVG document by including <style> tag in CDATA section. However, enclosing style within CDATA is less needed since CSS styles have less need for <, > or & characters. Therefore you can remove CDATA marker for CSS styles if you want.