Quantcast
Channel: How to parse input xml data to json in react with xml2js? - Stack Overflow
Viewing all articles
Browse latest Browse all 2

How to parse input xml data to json in react with xml2js?

$
0
0

I am trying to parse the input xml data to json in react with the help of xml2js.

import React, { useState } from "react";import xml2js from "xml2js";function Parser() {  const [xmlData, setXmlData] = useState({});  let parser = new xml2js.Parser();  parser.parseString(    `<email><to>Test</to><from>Test1</from><heading>Test email</heading><body>Email regards to xml data parsing in React</body></email>`,    function (err, result) {      console.log(result);      if (result) {        setXmlData(result);        return;      }      return;    }  );  return (<div>      Parse XML using ReactJs      {JSON.stringify(xmlData)}</div>  );}export default Parser;

But I am getting unlimited re render error. Can anyone help on this ?

Thanks in advance


Viewing all articles
Browse latest Browse all 2

Latest Images

Trending Articles





Latest Images