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

xml-wiz

v1.2.0

Published

XML generator

Downloads

3

Readme

xml-wiz

npm version

XML generator

Main features:

  • Automatic namespace handling
  • Function purity support

xml-wiz is an XML generator that focuses primarily on XML namespace handling. Using xml-wiz, there is no need to add namespace declarations or prefixes manually. It is sufficient to associate namespace URIs with nodes/attributes and the generator will put in the declarations and prefixes automatically.

The API is designed with function purity in mind. Many common XML generators (which are not JSON-based) require building all nodes and attributes in one place. In cases where some branches of the XML tree are built in different scopes, the XML object must around and altered as an argument, which breaks functional purity. In this API, there are no builder objects. Every node is its own JSON object. Child relations can be readily altered anywhere in the code, allowing complex structures to originate from multiple sources without having to pass a builder object around.

Usage

The simplest example is as follows:

const xmlWiz = require('xml-wiz');

const n1 = { name: 'Root' };
const n2 = { name: 'Child1' };
const n3 = { name: 'Child2' };
n1.children = [n2, n3];
const xml = xmlWiz(n1);

This generates the following XML (formatted for readability):

<Root>
  <Child1></Child1>
  <Child2></Child2>
</Root>

A more involved example with namespaces:

const NS_A = 'http://example.com/a';
const NS_B = 'http://example.com/b';

const node1 = {
  name: 'Node1',
  ns: NS_B,
  children: 'Hello there!',
};
const node2 = {
  name: 'Node2',
};
const root = {
  name: 'Root',
  ns: NS_A,
  attributes: [{ name: 'attr1', ns: NS_A, value: '3' }],
  children: [node1, node2],
};
const xml = xmlWiz(root);

Generated XML (formatted for readability):

<ns1:Root
    xmlns:ns1="http://example.com/a"
    xmlns:ns2="http://example.com/b"
    ns1:attr1="3">
  <ns2:Node1>Hello there!</ns2:Node1>
  <Node2></Node2>
</ns1:Root>

Note that the prefixes (ns1 and ns2) were not provided by the user, only the URIs are provided. Prefixes are generated automatically.

Nodes and attributes

xmlWiz() accepts a single object that represents the root node of the XML tree. The root node may contain other nodes as children, and any node may contain attributes. Node and attribute objects must contain the following keys to work as expected.

Node

| Key | Type | Required | Description | | :----------- | :---------------------------------- | :------: | :---------------------------------------------------------------------------------------------------------------------------------------------------------------- | | name | string | Yes | The name of the node. | | ns | string | No | The namespace URI of the node (not a prefix). | | localNs | boolean | No | If true, the namespace declaration is added to the node (in addition to the root node). | | attributes | object | list of objects | No | A single attribute or a list of the attributes associated with this node (formatted as described in these docs). | | children | string | object | list of objects | No | • A string representing a textual content.• An object representing a single child node.• A list of objects representing child nodes. |

Attribute

| Key | Type | Required | Description | | :------ | :----- | :------: | :------------------------------------------------- | | name | string | Yes | The name of the attribute | | ns | string | No | The namespace URI of the attribute (not a prefix). | | value | string | Yes | The value of the attribute. |