Skip to content

XML --> JSON --> XML with < or > in attribute value #6

Description

@ariutta

My XML attribute contains < and >. If I send it round trip (XML --> JSON --> XML), should the final XML match the initial XML?

Code snippet:

const fromXML = require("from-xml").fromXML;
const toXML = require("to-xml").toXML;

const data = fromXML('<object label="&lt;a href=&quot;https://www.ncbi.nlm.nih.gov/gene/59272&quot;&gt;ACE2&lt;/a&gt;" dataSource="ncbigene" identifier="59272" id="TjQ1G5W0H9Vnf-2-B7EA-1"> <mxCell style="rounded=1;whiteSpace=wrap;html=1;" vertex="1" parent="1"> <mxGeometry x="80" y="110" width="120" height="60" as="geometry" /> </mxCell> </object>');
console.log(JSON.stringify(data));

const xml = toXML(data);
console.log(xml);

Initial XML attribute: label="&lt;a href=&quot;https://www.ncbi.nlm.nih.gov/gene/59272&quot;&gt;ACE2&lt;/a&gt;"
Final XML attribute: label="<a href=&quot;https://www.ncbi.nlm.nih.gov/gene/59272&quot;>ACE2</a>"

&lt; and &gt; are changed after a round-trip conversion, but &quot; is not changed.

Thanks!

(This XML comes from the drawing tool at diagrams.net.)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions