pixl-xml icon indicating copy to clipboard operation
pixl-xml copied to clipboard

Allow Disabling / Configuring of xml_header

Open martindale opened this issue 7 years ago • 1 comments

It'd be convenient if this library offered the ability to compose raw XML strings, i.e., without including the xml_header + eol pair at the beginning of all composed documents.

martindale avatar Apr 05 '18 14:04 martindale

You can do this by passing 1 to the indent argument of XML.stringify(). By specifying an indent level of 1 instead of 0, it skips the header.

Example:

var XML = require('pixl-xml');

var xml_string = '<?xml version="1.0"?><Document>' +
        '<Simple>Hello</Simple>' +
        '<Node Key="Value">Complex</Node>' +
        '</Document>';

var doc = XML.parse( xml_string );

var xml_string = XML.stringify( doc, 'Document', 1, "", "" );
console.log( xml_string );

This outputs:

<Document><Node>Complex</Node><Simple>Hello</Simple></Document>

jhuckaby avatar Apr 06 '18 03:04 jhuckaby