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

fast-xml

v0.0.1

Published

(incomplete) fast XML parser with XSD support

Downloads

18

Readme

fast-xml

(Currently incomplete and not operational) streaming XML parser using node-expat (requires node-gyp to compile).

Uses XSD schema information to read XML into nice JavaScript structures.

Downloads schema files and keeps a local cache in the file system.

Handles arbitrarily large files using streaming.

Parsing XSD schema files

Schema handling is implemented in the xsd directory. Supported syntax elements are defined in its types subdirectory. Each element in the xsd namespace inherits from types.Base which has static and dynamic members that affect parser initialization. The Base class and its derived classes shouldn't have manually defined constructors, because the parser will instantiate objects to inspect the dynamic properties. Instead, an init function is called on constructed objects when creating them during actual parsing.

The static members are mirrored as dynamic members of BaseClass. Any constructor of a class derived from Base can then be used as if it was a BaseClass instance.

The static mayContain member function of syntax element types (classes derived from types.base) returns a list of other element types (defined as BaseClass instances) that it supports as direct children. The parser uses these to create a kind of state machine.

Syntax elements may also have attributes. They should be initialized to null in the class definition (the TypeScript compiler will automatically generate a constructor to initialize them). The parser will construct an instance of each class it finds, and examine its automatically constructed dynamic members. During parsing, they will then be automatically initialized to attributes found in the schema being parsed. Unknown attributes will be ignored.

The XSD parser proceeds in stages (the parser and all syntax element classes have correspondingly named methods):

  • init which calls define to bind named elements, attributes, types etc. to their scope and handles import and include declarations. The imports form a directed, possibly cyclic graph and can modify root scopes of arbitrary namespaces, so it's impossible to generally resolve references to other named things visible in scope before all imports have been processed.
  • resolve which resolves references by name. Because possible attributes and child elements can be defined through deeply nested references that can point to other namespaces, it's generally impossible to know them all before all references in all namespaces have been resolved.
  • TODO: transform which renames things to avoid naming conflicts between child elements and attributes (which will be merged into members of a single JSON object) and possibly deals with scope issues for TypeScript definition output.

TODO: after parsing, the resulting data structure should be exportable as JSON or a TypeScript definition file with ambient declarations of the XML namespaces.

License

The MIT License

Copyright (c) 2015 BusFaster Ltd