0
  1. Input: It have a json object, such as "root" object
  2. Output: and now, how to convert to a xml format like this:
  3. Program Language, you can use node, java,etc

Input json object:

"root" :{
   "Yylb": {
       "Yylb_id": [1,2]
     },
   "Fj": [
     {
      "Fjxx":1
     },
     {
     "Fjxx":2
     }
  ]
}

Outpu xml format:

<root>
   <Yylb>
      <Yylb_id>1</Yylb_id>
      <Yylb_id>1</Yylb_id>
   </Yylb>
   <Fj>
      <Fjxx>1</Fjxx>
   </Fj>
   <Fj>
      <Fjxx>2</Fjxx>
   </Fj>
</root>

2 Answers 2

1

Try using this Node module: https://www.npmjs.com/package/js2xmlparser.

Example:

var js2xmlparser = require("js2xmlparser");

var data = {
    "firstName": "John",
    "lastName": "Smith"
};

console.log(js2xmlparser("person", data));

> <?xml version="1.0" encoding="UTF-8"?>
> <person>
>     <firstName>John</firstName>
>     <lastName>Smith</lastName>
> </person>
Sign up to request clarification or add additional context in comments.

Comments

0

You can use xml-js

Steps to use:-

Install-Package:- npm install --save xml-js

then add code this snippet:-

var convert = require('xml-js');
var xml =
'<?xml version="1.0" encoding="utf-8"?>' +
'<note importance="high" logged="true">' +
'    <title>Happy</title>' +
'    <todo>Work</todo>' +
'    <todo>Play</todo>' +
'</note>';
var result1 = convert.xml2json(xml, {compact: true, spaces: 4});
var result2 = convert.xml2json(xml, {compact: false, spaces: 4});
console.log(result1, '\n', result2);

For more details Please visit :- xml-js

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.