michaelkourlas / node-js2xmlparser

Popular Node.js module for parsing JavaScript objects into XML
https://www.npmjs.org/package/js2xmlparser
Apache License 2.0
222 stars 52 forks source link

Not Escaping ">" In String Between Tags #74

Closed ziplokk1 closed 6 years ago

ziplokk1 commented 6 years ago

This is kind of a stupid edge case, but I need to have an XML string within an XML tag.

Example of what I need:

<Root>
  <Element>&lt;SubElement attr="abc"/&gt;</Element>
</Root>

Example of what is output:

<Root>
  <Element>&lt;SubElement attr="abc"/></Element>
</Root>

Is this a bug, or am I just doing something wrong here (other than the obvious XML within XML)?

ziplokk1 commented 6 years ago

If I create my XML string and then do:

const subelement = '<SubElement attr="abc">'.replace(/\>/g, '&lt;');
const xml = js2xmlparser.parse('Root', {Element: subelement});
console.log(xml);

it outputs '<?xml version=\'1.0\'?>\n<Root>\n <Element>&lt;SubElement attr="abc"&amp;lt;</Element>\n</Root>'

So I cant just replace the '>' because it encodes the ampersand as &amp;

ziplokk1 commented 6 years ago

It looks like this is an issue with the xmlcreate repo. I will open an issue there.

michaelkourlas commented 6 years ago

I've responded in the other issue you opened.