
Security News
Meet Socket at Black Hat and DEF CON 2025 in Las Vegas
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
js-parse-xml
Advanced tools
Install using NPM or Yarn:
npm i --save js-parse-xml
OR
yarn add js-parse-xml
ESM Imports
import { Parser, parseString, parseStringSync, parseFile, parseFileSync } from "js-parse-xml";
CommonJS Imports
const { Parser, parseString, parseStringSync, parseFile, parseFileSync } = require("js-parse-xml");
Synchronous Parsing
let json = parseStringSync("<xml>Example!</xml>");
// do whatever with the json here
let json = parseFileSync("file.xml");
// do whatever with the json here
Asynchronous Parsing
async function parse(string) {
let json = await parseString(string);
// do whatever with the json here
}
parse("<xml>Testing</xml>");
async function parse(file) {
let json = await parseFile(file, { stream: true });
// do something with the json
}
parse("large_file.xml");
Using the Parser Class
// strict:false will continue parsing if it finds error
let parser = new Parser({ strict: false });
// create stream and feed each chunk to the parser
let stream = fs.createReadStream("filename.xml", "utf-8");
stream.on("data", parser.feed);
stream.on("end", () => {
let json = parser.finish();
// do whatever with the json
});
XML Input
<space:test>
<example>
content
</example>
</space:test>
Parsed JSON Output
{
"test": {
"example": "content"
}
}
XML Input
<test>
<v>0.01e2</v>
<v>0003</v>
<v>-003</v>
<v>0x2f</v>
<v><![CDATA[ <xml> ]]></v>
</test>
Parsed JSON Output
{
"test": {
"v": [1, 3, -3, 47, "<xml>"]
}
}
Configure your parser with available options:
let options = {
encoding: "utf-8",
stream: false,
preserve_whitespace: false,
convert_values: true,
strict: true
};
The goal of this project is to be open source and community-driven. Therefore, contributing is welcomed, and any/all ideas and suggestions are taken into consideration. We welcome everyone to join our Discord server and post questions, comments, concerns, or feature requests! You can also navigate to our Github and open a new issue.
FAQs
lightweight Node-JS xml parser
We found that js-parse-xml demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
Security News
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.