davidcalhoun / jstoxml

JavaScript object to XML converter (useful for RSS, podcasts, GPX, AMP, etc)
MIT License
178 stars 23 forks source link

Skip indent for complex xml (or related solution) #56

Closed sknox131 closed 2 years ago

sknox131 commented 2 years ago

I am using your library to write bpmn and need an effective way to write CDATA. Right now, when I output my xml, it puts an indent after a CDATA value. I noticed in the code that there is a flag for marking complex xml values such that if there is an open bracket in the value, then an indent and a newline will be added to the document. Can there be an option to get around this? Possibly an '_xmlIsSimple' xml option? Or potentially some way to create CDATA without writing out the open and close brackets myself?

davidcalhoun commented 2 years ago

Thank you for the heads up, will look into this as soon as I can!

davidcalhoun commented 2 years ago

Thank you, I believe this is now fixed in v3 for CDATA automatically, please try it out. Thank you!

Example:

const content = {
    foo: {
        bar: `<![CDATA[
<B>Bold the letters in the content <EM>Next</EM>part.</B>
]]>`,
        baz: 's'
    }
};
const config = { indent: '    ' };
toXML(content, config);
/*
Output:
`<foo>
    <bar><![CDATA[
<B>Bold the letters in the content <EM>Next</EM>part.</B>
]]></bar>
    <baz>s</baz>
</foo>`
*/
sknox131 commented 2 years ago

Perfect! Thank you!