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 🙏

© 2025 – Pkg Stats / Ryan Hefner

xmjs

v1.1.3

Published

XML 1.0 parsing, stringifying, validating, converting to and from JSON

Downloads

13

Readme

XMJS

What's XMJS?

XMJS is an XML parsing library for JavaScript. It has a parse and a stringify method, similar to the built-in JSON library and a ton of more features!

Usage / Documentation

Importing

To use this library, you have to first import it by doing the following:

const XML = require("xmjs");

Parsing

For parsing XML, you can run the following:

XML.parse("<ExampleXML>hello world</ExampleXML>");
/*
{
    ExampleXML: {
        value: 'hello world',
        attributes: {}
    }
}
*/

This is how XMJS parses nested tags:

XML.parse("<SupportsNesting><NestedTag>I am a nested tag!</NestedTag></SupportsNesting>");
/*
{
    SupportsNesting: {
        NestedTag: {
            value: 'I am a nested tag!',
            attributes: {}
        }
    }
}
*/

XMJS also supports parsing attributes of tags:

XML.parse("<SomeTag hello=\"world\"></SomeTag>");
/*
{
    SomeTag: {
        value: '',
        attributes: {
            hello: 'world'
        }
    }
}
*/

XML.parse("<Person name=\"Jonathan\" surname=\"Doe\"><Job income=\"500$\"></Job></Person>");
/*
{
    Person: {
        Job: {
            value:'',
            attributes: {
                income: '500$'
            }
        },
        attributes: {}
    }
}
*/

XMJS supports XML arrays since version 1.1.0:

XML.parse(`
<Person name="John">
    <FavoriteFoods>
        <Food>Cheeseburger</Food>
        <Food>Pizza</Food>
        <Food>Broccoli</Food>
        <Food>Doner</Food>
    </FavoriteFoods>
</Person>
`);

/*
{
  Person: {
    FavoriteFoods: {
      Food: [
        {
          value: "Cheeseburger",
          attributes: {}
        },
        {
          value: "Pizza",
          attributes: {}
        },
        {
          value: "Broccoli",
          attributes: {}
        },
        {
          value: "Doner",
          attributes: {}
        }
      ]
    },
    attributes: {
      name: "John"
    }
  }
}
*/

Stringifying

XMJS can stringify JavaScript objects, just like how the JSON.stringify method does it

XML.stringify({
    Person: {
        Name: "Jonathan",
        Surname: "Doe",
        EMail: "[email protected]",
        Job: {
            Income: "500$"
        }
    }
});
/*
<Person>
    <Name>Jonathan</Name>
    <Surname>Doe</Surname>
    <EMail>[email protected]</EMail>
    <Job>
        <Income>500$</Income>
    </Job>
</Person>
*/

Validating

XMJS can validate XML through XML.validate:

XML.validate("<Tag>hello world</Tag>"); // Parses and returns { Tag: { value: 'hello world', attributes: {} } }

XML.validate("i am not valid XML"); // Returns false

XML To JSON

XMJS can convert XML data to JSON:

XML.xmlToJson("<Person name=\"Jonathan\" surname=\"Doe\"><Job income=\"500$\">Engineer</Job></Person>");
/*
{
    "Person": {
        "Job": {
            "value": "Engineer",
            "attributes": {
                "income": "500$"
            }
        },
        "attributes": {
            "name": "Jonathan",
            "surname":"Doe"
        }
    }
}
*/

JSON to XML

XMJS can also convert JSON data to XML:

XML.jsonToXml("{ \"Hello\": \"World\" }");
/*
<Hello>World</Hello>
*/

Changelog

1.0.0

  • Initial Release

1.0.1

  • Minor bug fixes

1.0.2

  • Minor bug fixes

1.0.3

  • Minor bug fixes

1.1.0

  • Added support for XML arrays
  • Added option disallowUnexpectedTokenError: allows unexpected tokens to exist in an XML document without throwing an error.
  • Added changelog to README.md

1.1.1

  • Fixed XML arrays not parsing correctly

1.1.2

  • Fixed last attribute overridng all other attributes in XML objects (<a b="c" c="d"></a> would actually only have attribute c)

1.1.3

  • Added ability to use - in XML keys