I've used xml-js - npm to get the desired result.
First of all I've installed xml-js via npm install xml-js
Then used the below code to get the output in json format
var convert = require('xml-js');
var xml = require('fs').readFileSync('./testscenario.xml', 'utf8');
var result = convert.xml2json(xml, {compact: true, spaces: 4});
console.log(result);
Answer from Dinesh on Stack OverflowI've used xml-js - npm to get the desired result.
First of all I've installed xml-js via npm install xml-js
Then used the below code to get the output in json format
var convert = require('xml-js');
var xml = require('fs').readFileSync('./testscenario.xml', 'utf8');
var result = convert.xml2json(xml, {compact: true, spaces: 4});
console.log(result);
You can use xml2json npm for converting your xml in to json. xml2json.
Step 1:- Install package in you project
npm install xml2json
Step 2:- You can use that package and convert your xml to json
let xmlParser = require('xml2json');
let xmlString = `<?xml version="1.0" encoding="UTF-8"?>
<TestScenario>
<TestSuite name="TS_EdgeHome">
<TestCaseName name="tc_Login">dt_EdgeCaseHome,dt_EdgeCaseRoute</TestCaseName>
<TestCaseName name="tc_Logout">dt_EdgeCaseRoute</TestCaseName>
</TestSuite>
<TestSuite name="TS_EdgePanel">
<TestCaseName name="tc_AddContract">dt_EdgeCaseHome,dt_EdgeCaseSpectrum</TestCaseName>
</TestSuite>
<TestSuite name="TS_EdgeRoute">
<TestCaseName name="tc_VerifyContract">dt_EdgeCaseRoute</TestCaseName>
<TestCaseName name="tc_Payment">dt_EdgeCaseRoute</TestCaseName>
</TestSuite>
<TestSuite name="TS_EdgeSpectrum">
<TestCaseName name="tc_ClientFeedback">dt_EdgeCaseSpectrum</TestCaseName>
</TestSuite>
</TestScenario>`;
console.log('JSON output', xmlParser.toJson(xmlString));
Hope this might be helps to you.
The KDL Document Language, an alternative to YAML/JSON/XML
Blazing fast XML parser to JSON for Node.js written in Rust
Convert XML to a (useful) JSON
HTML conversion into JSON
If the content (text, in your case) is within another tag, that content is a child of the tag. If the text is within a div, the div is the parent and the text is the child. So if you select the div, the content would obviously be in the children.
However your question seems less to do with html->JSON and more so on how to find content using cheerio. Cheerio is just server-side jQuery. So most, if not all, of jQuery’s methods can be used here, removing the need to traverse the JSON yourself.
More on reddit.comVideos
» npm install xml2js
» npm install simple-xml-to-json
» npm install xml-js
» npm install xml2json
» npm install xml-to-json-stream
» npm install xmltojson
» npm install @jdalton/simple-xml-to-json
» npm install rapid-xml-to-json
» npm install xml-json