2.0.5 • Published 2 years ago

js-parse-xml v2.0.5

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

NPM Downloads

Home of the fastest well-formed XML parser on NPM! Chat and ask questions with us on Discord. Try a demo by clicking here!

Features:

  1. Stream based.
  2. Can parse large files (Tested up to 700MB)
  3. 0 dependencies.
  4. Small package size.
  5. Fast parsing.
  6. Well-formed XML validation.
  7. Maintains tag order in object.
  8. Customizable whitespace handling.
  9. Parses content into correct data types (optional).

Getting Started :yum:

Install

npm i --save js-parse-xml OR yarn add js-parse-xml

ES6 imports import {Parser, parseString, parseStringSync, parseFile, parseFileSync} from "js-parse-xml"

ES5 imports const {Parser, parseString, parseStringSync, parseFile, parseFileSync} = require("js-parse-xml")

Usage

Synchronous

let json = parseStringSync("<xml>Example!</xml>")

// do whatever with the json here
let json = parseFileSync("file.xml")

// do whatever with the json here

Asynchronous

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")

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
})

Options

These are all of the available/default options

let options = {
    encoding: "utf-8",
    stream: false,
    preserve_whitespace: false,
    convert_values: true,
    strict: true
  }

Output :fire:

XML Input

<space:test>
    <example>
        content
    </example>
</space:test>

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>

JSON Output

{
    "test": {
        "v":[1,3,-3,47,"<xml>"]
    }
}

Contributing :pray:

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.

2.0.5

2 years ago

2.0.4

2 years ago

2.0.3

2 years ago

2.0.2

2 years ago

2.0.1

2 years ago

2.0.0

2 years ago

1.2.5-beta10

2 years ago

1.2.5-beta9

2 years ago

1.2.5-beta8

2 years ago

1.2.5-beta7

2 years ago

1.2.5-beta6

2 years ago

1.2.5-beta5

2 years ago

1.2.5-beta4

2 years ago

1.2.5-beta3

2 years ago

1.2.5-beta2

2 years ago

1.2.5-beta1

2 years ago

1.2.5-beta.1

2 years ago

1.2.5-beta.0

2 years ago

1.2.4

2 years ago

1.2.3

2 years ago

1.2.2

2 years ago

1.2.1

2 years ago

1.2.0

2 years ago

1.1.8

2 years ago

1.1.7

2 years ago

1.1.6

2 years ago

1.1.5

2 years ago

1.1.4

2 years ago

1.1.3

2 years ago

1.1.2

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago