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

ordxml

v0.3.3

Published

An XML parser that maintains consistent order (tags, text, etc), is very flexible, very forgiving -- and also provides ability to define what tag types do, using javascript code.

Downloads

18

Readme

ordxml

Note: This is a rewrite of OrdXml and backward compatibility is lost since version 0.2.7.

Originally, I developed OrdXML because I couldn't find an XML parser for Node.js that kept text and tags in order. That is, after parsing an XML document, the text contained in a tag and the sub-tags contained were each put in different arrays. This might have been ok for just parsing data but I wanted to develop a framework for application development.

OrdXML will parse XML data but also has extended capabilities, if you want to use them. For example, OrdXML will accept different data types assigned in tag headers:

<mytag name="Joe" age=42 married=yes employee/>

The above tag will translate each assignment to its appropriate JavaScript data type. An unquoted value of "yes" or "no" becomes JavaScript boolean; the same for "true" or "false". And notice the "employee" flag at the end. This is assigned a JavaScript value of True else undefined if not present (naturally).

OrdXML also supports arrayed assignments in two different ways and of mixed types:

<mytag foods="apples","pancakes","sandwhiches" foods="bananas" extradata="whatever",42,no/>

The above assigns an array of 3 strings to foods, then adds another (bananas) to the same array. Extradata is also assigned an array but of string, number, and boolean values.

Finally, a tag in OrdXML can have an ID that is not a property, as shown below:

<mytag myid: propa="hello" propb="goodbye"/>

In the above "mytag" is the type of tag while "myid" is meant to uniquely identify the tag, at its hierarchical level in the XML document. This is my own philosophical addition to XML. A tag type is essentially a class while its ID uniquely identifies the instance of that class. Unlike a property named "id" in HTML (for example), this ID is not a property. It should be unique not throughout the document but at its level within the document. This way, a reference to data may be made through period notation, such as:

<app myapp: version="1.0.1">
	<dialog profile: name="Joe" age=52>
	</dialog>
</app>

So you might reference the user's name and age like:

console.log( myapp.profile.prop.name );
console.log( myapp.profile.prop.age );

Installation

npm install ordxml

Usage Example

# Load and Instantiate
const ordxml = require('ordxml').ordxml;

# Parse and show some data in XML
let xmlData = '<say message="Hello World!"/>\n<mystuff whos="mine" not="yours"> <item>coffee</item><item>phone</item> </mystuff>';
let data = ordxml.parseDoc(xmlData)
console.log( JSON.stringify( data, null, '  ' ) );

Roap Map

  • Config option for making ordxml a drop-in replacement for "fast-xml-parser"
  • Config option for making ordxml a drop-in replacement for "xml2js"
  • Add back tag function definer syntax in older version, e.g. <mytag{ javascript code }/>.
  • Add condition data type, e.g. <mytag cond=( ..logic .. )/>
  • Add time data type, e.g. <mytag time=\2021-07-29 17:50:28\/>

Bugs

  • It has been rewritten so bugs will come, I am sure.