Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

15 Commits

Repository files navigation

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.

varxml='<?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>';varXML=require('simple-xml');console.log(JSON.stringify(XML.parse(xml)));// {"items":{"item":[{"value":"Item 1"},{"value":"Item 2"},{"value":"Item 3"}]}}varxml='<?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.

varobj={"items":{"item":[{"value":"Item 1"},{"value":"Item 2"},{"value":"Item 3"}]}}varXML=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>

About

A naive XML parser and builder based on libxmljs for NodeJS

Resources

Stars

5 stars

Watchers

4 watching

Forks

Releases

Packages

Used by

Contributors

Languages