simple-xml
DefinitelyTyped icon, indicating that this package has TypeScript declarations provided by the separate @types/simple-xml package

0.0.10 • Public • Published

XML

A naive XML parser and builder based on libxmljs implementing the JSON api. This module was created as a simple way to parse and build xml for web services such as SOAP. It supports parsing arrays of elements or attributes, but not both intermingled.

Usage

npm install simple-xml --save

parse(xml string or libxml document)

Parse a string or a libxml document or element into a Plain Old Javascript Object.

var xml = '<?xml version="1.0" encoding="UTF-8"?><items><item><value>Item 1</value></item><item><value>Item 2</value></item><item><value>Item 3</value></item></items>';
var XML = require('simple-xml');
console.log(JSON.stringify( XML.parse(xml) ));
 
// {"items":{"item":[{"value":"Item 1"},{"value":"Item 2"},{"value":"Item 3"}]}}
 
var xml = '<?xml version="1.0" encoding="UTF-8"?><items><item>Item 1</item><item>Item 2</item><item>Item 3</item></items>';
console.log(JSON.stringify( XML.parse(xml) ));
 
// {"items":{"item":["Item 1","Item 2","Item 3"]}}
 

stringify(object)

Transforms an object into a simple xml string representation.

var obj = {"items":{"item":[{"value":"Item 1"},{"value":"Item 2"},{"value":"Item 3"}]}}
var XML = require('simple-xml');
console.log( XML.stringify(obj) );
 
// <items><item><value>Item 1</value></item><item><value>Item 2</value></item><item><value>Item 3</value></item></items>
 

Package Sidebar

Install

npm i simple-xml

Weekly Downloads

1

Version

0.0.10

License

BSD-2-Clause

Last publish

Collaborators

  • jtblin