CDATA content is added directly to the containing element's children array as a string.
Content before a root <svg> element, including an XML declaration or doctype, is available on that element's metadata property.
The parser is designed for input containing one top-level element.
Malformed input throws an Error with its zero-based line and column location and a source snippet:
parse('<svg><path></svg>');// Error: Expected closing tag </svg> to match opening tag <path> (0:16)//// <svg><path></svg>// ^
Source snippets include at most one surrounding line on each side and are cropped to 80 columns. Ellipses indicate omitted content. Empty or whitespace-only input throws Error: SVG input is empty.
Scope
svg-parser is a lightweight, purpose-built parser rather than a validating XML parser or DOM implementation. It is useful when you need a serializable syntax tree for common SVG markup. If you need full XML validation or browser DOM behavior, use a dedicated XML parser instead.
Development
npm installnpm test # build and run the test suitenpm run lint # check source and formattingnpm run build # rebuild dist/
Security
See SECURITY.md for vulnerability reporting instructions.