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
- Host: GitHub
- URL: https://github.com/thomasjo/xml.js
- Owner: thomasjo
- License: mit
- Created: 2014-05-27T18:30:46.000Z (about 12 years ago)
- Default Branch: master
- Last Pushed: 2014-05-27T18:33:56.000Z (about 12 years ago)
- Last Synced: 2025-01-21T04:41:39.163Z (over 1 year ago)
- Language: JavaScript
- Size: 125 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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'
```