Skip to content

imotro/xml-parser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

xml-parser

parse XML to objects in Node.js or Browser.

Notice

the functionality of this parser is very limited beyond the parsing of XML. there are no special commands to select certain elements based on attributes (selectors). simply refrence an element the way you would and retreive attributes the way you would in browsers (do i really need this notice..?)

Overview

this goes over every character in the provided XML and turns its attributes and inner value to JSON

Usage

NOTE: refrence children directly, dont use parent.parent.parent.child, just do child. attributes still work the same as you would expect I understand this may become an issue when having multiple children with the same name. A solution is being developed.

XMLParser.parse('<xml>')
XMLParser.isXML('<xml>')

this library does not use any built in APIs or modules, so it works in node.js and browsers

Examples:

Node.js

//Node.js CommonJS
const XMLParser = require('xml.js');
//Node.js ESM
import XMLParser from 'xml.js'

const parser = new XMLParser()
const XML = '<element attr="val" attr2=val2>inner value</element>'
const output = parser.parse(XML)
console.log(output) // { element: { attr: 'val', attr2: 'val2' }, value: 'inner value' }

Browser

<script src="xml.js"></script>
<script>
const parser = new XMLParser()
const XML = '<element attr="val" attr2=val2>inner value</element>'
const output = parser.parse(XML)
console.log(output) // { element: { attr: 'val', attr2: 'val2' }, value: 'inner value' }
</script>

you can download index.js file above into your project or use This link

Releases

No releases published

Packages

No packages published