JavaScript HTML
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
out xsd; add purchaseorder example Jul 31, 2017
test xsd; add purchaseorder example Jul 31, 2017
.gitignore XSD2json optional laxURI processing Apr 13, 2016
.npmignore Omit tests etc from npm package Aug 23, 2016
.travis.yml Swap node7 for 8 on travis builds Jul 31, 2017
LICENSE Last vestiges of the old package name Mar 3, 2016
README.md Update README.md Nov 30, 2016
jgeXml.js Improve handling of sError states Mar 8, 2016
jpath.js jptr; fix for ~0/~1 in prop Oct 6, 2017
json2xml.js XSD unions and lists Jun 30, 2016
json2yaml.js JSHINT nits plus missed bookstore.jpath file Mar 6, 2016
jsont.js Now passes test #4 from the JSONT examples Mar 3, 2016
package.json 0.3.8 Oct 6, 2017
pullparser.js Allow encoding to be specified for push/pull examples Mar 5, 2016
pushparser.js Allow encoding to be specified for push/pull examples Mar 5, 2016
testRunner.js testRunner: honour NODE_DISABLE_COLORS Nov 29, 2016
testfrag.js Include xmlWrite / fragments in unit tests Mar 5, 2016
testj2x.js Reorder parameters for json2xml Mar 3, 2016
testj2y.js json2yaml - first cut Mar 3, 2016
testjpath.js XSDtoJson type improvements May 17, 2016
testjsont.js Comment change only Feb 28, 2016
testx2j.js Fixes to x2j coerceTypes Jul 18, 2016
testx2x.js jgeXml CDATA support Mar 4, 2016
testxsd2j.js xsd2json; allow variable namespace prefixes for xml-schema Jul 31, 2017
xml2json.js Fixes to x2j coerceTypes Jul 18, 2016
xmlWrite.js JSHINT nits plus missed bookstore.jpath file Mar 6, 2016
xsd2json.js xsd2json; allow variable namespace prefixes for xml-schema Jul 31, 2017

README.md

jgeXml - The Just-Good-Enough XML Toolkit

Build status Join the chat at https://gitter.im/MikeRalphson/jgeXml

Share on Twitter Follow on Twitter

jgeXml provides an event-driven parser to process XML 1.0 / 1.1. Both pull and push modes are supported. Tools are included for writing XML (documents or fragments) and to convert between XML and JSON (one way JSON to YAML conversion is also supported).

The code has no dependencies on other modules or native libraries.

Setting up a push-parser is as simple as:

	var jgeXml = require('jgeXml');
	var result = jgeXml.parse(xml,function(state,token) {
		//...
	});

Events (stateCodes)

sDeclaration
sDocType
sDTD
sElement
sAttribute
sValue
sEndElement
sContent
sComment
sProcessingInstruction
sCData
sError
sEndDocument

No event is generated for ignoreable whitespace, unlike SAX. Empty elements are normalised into sElement/sEndElement pairs.

Notes

jgeXml is a non-validating parser. It attempts to report if the XML is well-formed or not.

Both when reading and writing, attributes follow after the element event, and in the order they are given in the source.

When converting to JSON, the attributePrefix (to avoid name clashes with child elements) is configurable per parse.

In JSON, child elements can be represented as properties (the default) or objects (exposing the parser's intermediary state).

The parser by default treats all content as strings when converting to JSON, optionally data can be coerced to primitive numbers or null values.

The utility xsd2json can convert most XML Schemas to JSON schema draft 4. XSD's may of course be converted to JSON simply as if they were XML documents too.

Experimental JSONPath and JSONT utilities are under development.

Limitations

jgeXml is currently schema agnostic and staunchly atheist when it comes to DTDs. It can parse XML documents with schema information, but it is up to the consumer to interpret the namespace portions of element names. It can parse internal DTDs, but does nothing with them. xmlWrite minimally supports DTDs but you must build them and the DOCTYPE yourself.

The parser is string-based; to process streams, read the data into a string first. It may be memory intensive on large documents.

Examples

See testx2x for parsing XML to XML, testx2j for parsing XML to JSON, testj2x for converting JSON to XML, testj2y for converting JSON to YAML, testfrag for writing XML fragments, testjpath for JSONPath examples, testjsont for JSONT examples and pullparser / pushparser for how to set up and run the parser.