Skip to main content

Remove XML Declaration

Default

Removes the XML declaration from the document.

The SVG language is based on XML, and is XML compatible, so editors often include an XML declaration.

An XML declaration is the line at the top of an XML file to indicate document meta-data, like encoding and which version of the XML specifications it adheres to.

<?xml version="1.0" encoding="UTF-8"?>

The XML declaration is optional in XML 1.0, but mandatory in the XML 1.1. If the XML declaration is omitted, the document is assumed to follow the XML 1.0 specifications, which won't impact SVG documents.

It can be safely removed without impacting compatibility with SVG clients. However, some tools may fail to detect the MIME-type as image/svg+xml if this is removed.

Usage

svgo.config.js
module.exports = {
plugins: [
"removeXMLProcInst"
]
}

Demo

Live Editor
const svg = `
<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg" viewBox=" 0 0  150 100 " width="150">
  <!-- Created with love! -->
  <defs>
    <ellipse cx="50" cy="50.0" rx="50.00" ry="auto" fill="black" id="circle"/>
  </defs>
  <g>
    <use href="#circle" transform="skewX(16)"/>
    <rect id="useless" width="0" height="0" fill="#ff0000"/>
  </g>
</svg>
`;

const svgoConfig = {
  js2svg: { indent: 2, pretty: true },
  plugins: [
    "removeXMLProcInst"
  ]
}

render(<SvgoPreview svg={svg} svgoConfig={svgoConfig}/>);
Result
Loading...

Implementation