npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

jgexml

v0.4.4

Published

The Just-Good-Enough XML Toolkit

Downloads

168,382

Readme

jgeXml - The Just-Good-Enough XML Toolkit

Build status Join the Mermade Slack

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.

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

Setting up a push-parser is as simple as:

const jgexml = require('jgexml');
const 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 xsd2json utility can convert most simple 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.

CLI commands

  • xml2json - convert XML to JSON.
  • json2xml - convert JSON to XML.
  • xsd2json - convert XSD to JSON Schema.

Examples

See in the examples directory: xml2xml.js for parsing XML to XML, fragment.js for writing XML fragments, jpath.js for JSONPath examples, jsont.js for JSONT examples and pullparser.js / pushparser.js for how to set up and run the parser.