The Wayback Machine - https://web.archive.org/web/20230227072804/https://github.com/ricardofbarros/parser-xml2json
Skip to content

ricardofbarros/parser-xml2json

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
lib
 
 
src
 
 
 
 
 
 
 
 
 
 
 
 

Parser XML 2 JSON

Blazing fast XML parser to JSON written in Rust (node2object).

Requirements

Usage

const parser = require('parser-xml2json')

const xml = `
  <population>
    <entry>
      <name>Alex</name>
      <height>173.5</height>
    </entry>
    <entry>
      <name>Mel</name>
      <height>180.4</height>
    </entry>
  </population>
`

parser.parseString(xml, (err, res) => {
   ...
})

parser.parseFile('/a/xml/file/somewhere.xml', { object: true }, (err, res) => {
  ...
})

API

parseString(xmlString[, options], callback)

  • xmlString - A string that represents an XML
  • options - an optional object where:
    • object - Parse JSON string to Object. default false
  • callback - a function with the signature function (err, result)

parseFile(filePath[, options], callback)

  • filePath - Relative or absolute path to an .xml file
  • options - an optional object where:
    • object - Parse JSON string to Object. default false
  • callback - a function with the signature function (err, result)

Benchmark

Results from a i7 2.2 Ghz

Package                 Time taken
----------------------  ----------
parser-xml2json (rust)  0.0468 s
xml2js (js)             0.1286 s
xml2json (js and c++)   0.1329 s

How to run the benchmark script on your machine

npm i
npm i benchmark/
node benchmark/index.js

License

MIT

About

🔥 Blazing fast XML parser to JSON for Node.js written in Rust 🔥

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published