0.0.5 • Published 3 years ago

node-xml-parser v0.0.5

Weekly downloads
-
License
ISC
Repository
-
Last release
3 years ago

node-xml-parser

Very simple and intuitive Node JS module that validates, parses and builds XML.


Validating XML

import { validateXML } from 'node-xml-parser'

const goodXML = '<document><text>Hello, World</text><symbol data="!"/></document>'
const badXML = '</document><text Hello, World><!/></doc>'

// Yes, it's as easy as that:

validateXML(goodXML) // > true
validateXML(badXML) // > false

Parsing XML

import { parseXML } from 'node-xml-parser'

const XML = '<document><text>Hello, World</text><symbol data="!"/></document>'

parseXML(XML)

/*
	Features clean, easily readable output:

	XMLNode {
		tag: 'document',
		attributes: Map(0) {},
		children: [
			XMLNode {
				tag: 'text',
				attributes: Map(0) {},
				children: [
					XMLNode {
						tag: '@text',
						attributes: Map(1) { data -> 'Hello, World' },
						children: []
					}
				]
			},
			XMLNode {
				tag: 'symbol',
				attributes: Map(1) { data -> '!' },
				children: []
			}
		]
	}
*/

Building XML

import { buildXML, XMLNode } from 'node-xml-parser'

// Wow, so readable!

const xml = new XMLNode('document', {}, [
	new XMLNode('text', {}, [
		'Hello, World'
	]),
	'!'
])

buildXML(xml, { indentationSize: 2, indentationType: 'spaces' })

/*
	Prettiest output you have ever seen:

	<document>
		<text>
			Hello, World
		</text>
		!
	</document>
*/

Options for buildXML:

interface XMLBuilderOptions {
	indentationSize: number             // Default: 1
	indentationType: 'tabs' | 'spaces'  // Default: 'tabs'
	seperator: string                   // Default: '\n'
	enableSelfClosingTags: boolean      // Default: true
}
0.0.5

3 years ago

0.0.4

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago

1.0.0

6 years ago