0

I have XML document that I am trying to convert to JSON but some of the string fields have HTML tags in them. The source XML looks like this:

<title>
    <html>
        <p>test</p>
    </html>
</title>

i have tried npm packages like xml2js and fast-xml-parser. They are parsing html tags also to json. can anyone suggest any other npm package or solution that would be helpful

Expected output should be:

{
    "title": "<html><p>test</p></html>"
}
1
  • 1
    That isn't string data. If it was string data then either the special characters would be escaped (e.g. < would be &lt;) or would be wrapped in CDATA markers. Commented Aug 25, 2021 at 9:25

1 Answer 1

1

You can try fast-xml-parser with stopNodes option to parse a node as a string.

let jsonObj = parser.parse(xmlData,{
    stopNodes = ["title"]
});
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.