1 | xml-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
|
15 | XMLLite.findChildNode(doc, query);
|
16 | XMLLite.findChildNodes(doc, query);
|
17 | XMLLite.findOrCreateChildNode(doc, query);
|
18 | XMLLite.removeChildNode(doc, query);
|
19 | XMLLite.eachChildNode(doc, query, callback);
|
20 | // ...
|
21 | ```
|
22 |
|
23 | ### Formatting
|
24 |
|
25 | ```javascript
|
26 | XMLLite.beautify(xml, indent);
|
27 | XMLLite.uglify(xml, preserveComments);
|
28 | XMLLite.sanitize(xml, reverse);
|
29 | // ...
|
30 | ```
|
31 |
|
32 | Actually, 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 |
|
36 | 1. A reasonable need for usage in both Node.js and Browsers
|
37 | 2. 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 |
|
41 | 1. It **works exactly the same in both Node.js and Browsers**
|
42 | 2. The browser version is supper **light-weight**([dist/xml-lite.js](./dist/xml-lite.js))
|
43 | 3. **Convenient** APIs for converting between xml/js/json/DOM, and lots of helpers to maintain the data structures
|
44 | 4. 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 |
|
55 | In Node.js
|
56 |
|
57 | ```javascript
|
58 | const XMLLite = require('xml-lite');
|
59 | ```
|
60 |
|
61 | Command line client
|
62 |
|
63 | ```shell
|
64 | $ xml-lite --help
|
65 | ```
|
66 |
|
67 | In browsers
|
68 |
|
69 | ```html
|
70 | <script src="$path/to/xml-lite/dist/xml-lite.js"> <!-- window.XMLLite is available -->
|
71 | ```
|
72 |
|
73 | In browsers with webpack
|
74 |
|
75 | ```javascript
|
76 | import 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/
|