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

node-xmler

v0.1.1

Published

A simple package for creating XML elements

Downloads

3

Readme

XMLer

Build Status

XMLer is a simple package for creating XML elements. It allows elements to be created as JavaScript objects, adding attributes and child elements to the element, and provides a way to easily convert the element into an XML string.

Getting Started

Installation

$ npm install node-xmler

Usage

var xmler = require('node-xmler');

var cat = new xmler.Element('cat');
var name = new xmler.Element('name', 'Mr. Meowgi');
var breed = new xmler.Element('breed', 'Munchkin');

breed.addAttribute({
  key: 'purebred',
  value: 'true'
});

cat.addElement(name);
cat.addElement(breed);

var xml = cat.getXML();
console.log(xml);

The output of the console.log(xml) will be:

<cat>
  <name>Mr. Meowgi</name>
  <breed purebred="true">Munchkin</breed>
</cat>

In Depth

Creating an Element

An element can be created by specifying its name and optionally its body content in the arguments.

var cat = new xmler.Element(name, [body]); // <name>body</name>

Note: The body content should be plain text with any required inline XML

Adding Attributes

Attributes are objects that have key and value fields and can be added to an element's attributes as a single object or as part of an array of attributes.

addAttribute(attribute)

var cat = new xmler.Element('cat');
var attr = { key: 'color', value: 'grey' };
cat.addAttribute(attr); // <cat color="grey"...

addAttributes(attributes)

var cat = new xmler.Element('cat');
var attr = [
  { key: 'color', value: 'grey' },
  { key: 'cute', value: 'true' }
];

cat.addAttributes(attr); // <cat color="grey" cute="true"...

Adding Child Elements

Child elements can be added in similar fashion to attributes, either as a single object or as an array of children.

addElement(element)

var cat = new xmler.Element('cat');
var name = new xmler.Element('name', 'Mr. Meowgi');
cat.addElement(name); // <cat><name>Mr. Meowgi</name></cat>

addElements(elements)

var cat = new xmler.Element('cat');
var children = [
  new xmler.Element('name', 'Mr. Meowgi'),
  new xmler.Element('breed', 'Munchkin')
];

cat.addElements(children); // <cat><name>...</name><breed>...</breed></cat>

Converting to XML

You can convert an element along with any children to an XML string using the getXML() function.

getXML()

var cat = new xmler.Element('cat');
var xml = cat.getXML(); // Your element as an XML string

Running Tests

Tests are written using mocha and chai and can be run through gulp.

$ npm install -g gulp mocha
$ npm test