mtXml

XML Parser that maintains the order of elements and is otherwise very forgiving.

mtXml (formerly OrdXML) parses XML into a plain JavaScript data object while keeping elements and the text between them in document order. Most Node.js parsers split tags and text into separate arrays — fine for pulling out data, awkward for building tools or frameworks. mtXml keeps the sequence intact, and it's forgiving of malformed XML.

Highlights

  • Order-preserving. Text and sub-tags stay in the order they appear, so a parsed document still reads like the original — ideal for data acquisition and tool development alike.
  • Literal data types. Attribute values translate to real JavaScript types: numbers, and yes/no or true/false become booleans.
  • Flag attributes. A bare attribute like employee is set to true, and is simply undefined when absent.
  • Arrays in attributes. Assign comma-separated values — even of mixed types — to a single attribute, repeating the name to append.
  • Tag instance IDs. Give a tag a unique ID at its level (<dialog profile: name="Joe"/>) and reference data by dotted path — a tag type acts like a class, its ID like an instance.
  • Forgiving by design. Recognizes Matthew's XML extensions; pass a flag to opt into extended parsing.

A taste

const ordxml = require('ordxml').ordxml;

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, '  ' ) );

Installation

Install from npm, or clone the source:

npm install ordxml

git clone https://github.com/Solifugus/mtXml.git

Downloads & installation

Builds are coming soon. Grab the source from GitHub for now.