An open API service indexing awesome lists of open source software.

https://github.com/thomasjo/xml.js

A simple JavaScript library for working with XML data
https://github.com/thomasjo/xml.js

Last synced: over 1 year ago
JSON representation

A simple JavaScript library for working with XML data

Awesome Lists containing this project

README

          

XML.js
======
A minimalistic library for working with XML in JavaScript. Supports converting to and from XML,
in a simple, straightforward manner.

Example usage
-------------
Converting an XML document, in this case, in the form of a string, to a JavaScript object

```js
var obj = XML.objectify(
"" +
" IBM" +
" " +
" " +
" " +
" 8/5/2005" +
" " +
" " +
""
);

/*
obj = {
"stock-quote": {
"@market": "NASDAQ",
symbol: {
"#text": "AAPL"
},
price: [
{ "@type": "ask", "@value": "412.76" },
{ "@type": "bid", "@value": "413.5" }
],
when: {
date: { "#text": "2013-06-21" },
time: { "#text": "22:09" }
}
}
}
*/
```

Likewise, we can convert from a JavaScript object to XML

```js
var xml = XML.stringify({
"stock-quote": {
"@market": "NASDAQ",
symbol: {
"#text": "AAPL"
},
price: [
{ "@type": "ask", "@value": "412.76" },
{ "@type": "bid", "@value": "413.5" }
],
when: {
date: { "#text": "2013-06-21" },
time: { "#text": "22:09" }
}
}
});

// xml = 'AAPL2013-06-21'
```