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

axml

v0.2.2

Published

Xml Parser - convert Xml to JsonML.

Downloads

3

Readme

#Axml

Xml parser and serializer, JsonML.

Npm version   Npm download   Build Status   Coverage Status   Dependencies

Overview

Axml is a simple xml converter. It convert Xml to JsonML form which is easier to manipulate using javascript. JsonML is a makup language used to map XML document.

The parser support comments, CData, doctype. However JsonML doesn't support those. The parser can be overwrite to form any other object capable to support data.

Install

npm install axml

API

The axml parser overwrite the Node.js stream object. It can be used and pipe with any others stream object (compression, encryption...). However the easiest way to use it is to use the static methods.

Static API

To read a xml file you can use the asynchrone function readFile.

var axml = require ('axml');
axml.readFile (uri, function (err, data) {
  // data is a JsonML object.
});

To convert JsonML back to Xml, you can use the stringify method.

var str = axml.stringify(data, { eol:'\n', indent:'  ' });

Stream API

If you wish to have better control on the process, you can create a parser instance. This instance is a stream.Transform object. You can know more on Node.Js documentation.

var axml = require ('axml');
var stream = new axml();
var stream = fs.createReadStream (uri)
stream .on('finish', function(err) {
  console.log (stream.getDocument());
})
fs.createReadStream(uri).pipe (stream);

Helper methods

Here is some methods to help you deal with JsonML element. Note that some of this function may trigger an exception is the data is not recognize as a JsonML element.

axml.JsonMl.start (data) Allow to know the index of the first child element on a JsonML element. Simpler it return 2 is the element contains arguments or 1 if not.

axml.JsonMl.name (data) This function will return the name of the JsonML element. Note that this can be replace by data[0]`, but the function also embed a type check.

axml.JsonMl.attributes (data) This function return a javascript object that contains attributes of the element. Note that this method never return a null pointer, but an empty object in case there is no argument specified.

axml.JsonMl.istag (data) Return true if the object is equivalent to an element node.

axml.JsonMl.istext (data) Return true if the object is equivalent to a text node.

Plugin-In

At creation of the instance, the axml class take a optional object as argument. Here's an hint, full explanation is currently on writing.

var parser = {
  create:function() { return new docFactory(); },
  compile:function(docFactory) { return docFactory.docObj; },
  TEXT:function(docFactory, data) {},
  ELEMENT:function(docFactory, data) {},
  COMMENT: my_parser,
  DECLARATION:null,
  DOCTYPE:null,
  CDATA:null,
};

function my_parser (docFactory, data) {
  // data = { offset: 0, type: '', literal: '',  };
};

JsonML

JsonML, the JSON Markup Language is a lightweight markup language used to map between XML (Extensible Markup Language) and JSON (JavaScript Object Notation)1.

JsonML allows any XML document to be represented uniquely as a JSON string. The syntax uses:

  • JSON arrays to represent XML elements;
  • JSON objects to represent attributes;
  • JSON strings to represent text nodes.

XML

<person created="2006-11-11T19:23" modified="2006-12-31T23:59">
    <firstName>Robert</firstName>
    <lastName>Smith</lastName>
    <address type="home">
        <street>12345 Sixth Ave</street>
        <city>Anytown</city>
        <state>CA</state>
        <postalCode>98765-4321</postalCode>
    </address>
</person>

JsonML

["person",
  {"created":"2006-11-11T19:23",
   "modified":"2006-12-31T23:59"},
  ["firstName", "Robert"],
  ["lastName", "Smith"],
  ["address", {"type":"home"},
    ["street", "12345 Sixth Ave"],
    ["city", "Anytown"],
    ["state", "CA"],
    ["postalCode", "98765-4321"]
  ]
]

License

This code is under the modified BSD license.


  1. the definition of JsonMl is base on the Wikipedia article