UNPKG

2.01 kBMarkdownView Raw
1xml-lite
2========
3
4**Maintaining XML** in pure javascript (IN BOTH NODE.JS & BROWSERS) [Homepage][homepage]
5
6## Maintaining?
7
8### Converting
9
10![converting](./doc/uml/converting.png)
11
12### Editing/Traversing
13
14```javascript
15XMLLite.findChildNode(doc, query);
16XMLLite.findChildNodes(doc, query);
17XMLLite.findOrCreateChildNode(doc, query);
18XMLLite.removeChildNode(doc, query);
19XMLLite.eachChildNode(doc, query, callback);
20// ...
21```
22
23### Formatting
24
25```javascript
26XMLLite.beautify(xml, indent);
27XMLLite.uglify(xml, preserveComments);
28XMLLite.sanitize(xml, reverse);
29// ...
30```
31
32Actually, you can get the js object from `XMLLite.xml2js(xml)`, do whatever you want, and convert it back to xml again with `XMLLite.js2xml(obj)`.
33
34## Why?
35
361. A reasonable need for usage in both Node.js and Browsers
372. A more reasonable need to use native APIs(DOMParser/XMLSerializer) to speed up the maintaining process and keep the library thin
38
39## Why `xml-lite`?
40
411. It **works exactly the same in both Node.js and Browsers**
422. The browser version is supper **light-weight**([dist/xml-lite.js](./dist/xml-lite.js))
433. **Convenient** APIs for converting between xml/js/json/DOM, and lots of helpers to maintain the data structures
444. Super **fast**. it takes less than 30ms to convert an xml document with over 1,000 nodes into a js object
45
46## Install
47
48```shell
49$ npm install xml-lite --save
50$ npm install xml-lite -g
51```
52
53## Usage
54
55In Node.js
56
57```javascript
58const XMLLite = require('xml-lite');
59```
60
61Command line client
62
63```shell
64$ xml-lite --help
65```
66
67In browsers
68
69```html
70<script src="$path/to/xml-lite/dist/xml-lite.js"> <!-- window.XMLLite is available -->
71```
72
73In browsers with webpack
74
75```javascript
76import XMLLite from 'xml-lite/lib/index-browser';
77```
78
79## [Demo][homepage]
80
81## [API](./doc/api.md)
82
83## [JSON spec](./doc/json-spec.md)
84
85## [Roadmap](./doc/roadmap.md)
86
87## [Projects using xml-lite](./doc/projects-using-xml-lite.md)
88
89## [Contributing](./doc/contributing.md)
90
91[homepage]: https://leungwensen.github.io/xml-lite/