Skip to content

Conversation

@rgrove
Copy link
Owner

@rgrove rgrove commented Jan 29, 2023

When true, an XmlDeclaration node representing the XML declaration (if there is one) will be included in the parsed document. When false, the XML declaration will be discarded. The default is false, which matches the behavior of previous versions.

This option is useful if you want to preserve the XML declaration when later serializing a document back to XML. Previously, the XML declaration was always discarded, which meant that if you parsed a document with an XML declaration and then serialized it, the original XML declaration would be lost.

const { parseXml } = require('@rgrove/parse-xml'); let xml = '<?xml version="1.0" encoding="UTF-8"?><root />'; let doc = parseXml(xml, { preserveXmlDeclaration: true }); console.log(doc.children[0].toJSON()); // => { type: 'xmldecl', version: '1.0', encoding: 'UTF-8' }

This is the first half of #30.

/cc @wooorm

@wooorm
Copy link

wooorm commented Jan 29, 2023

Very cool!!

@rgrove rgrove merged commit 038cbd6 into next Jan 29, 2023
@rgrove rgrove deleted the xml-decl branch January 29, 2023 21:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants