1 | # xmlom - a tiny XML object model
|
2 |
|
3 | ## Usage
|
4 |
|
5 | ### `xmlom.parseString(str)`
|
6 |
|
7 | Parse an XML String.
|
8 |
|
9 | Returns a Promise which resolves to a Document.
|
10 |
|
11 | ```js
|
12 | var xmlom = require('xmlom');
|
13 | xmlom.parseString('<res><foo>bar</foo></res>').then(function (doc) {
|
14 | doc.find('foo').value; // "bar"
|
15 | }).catch(function (error) {
|
16 | // parsing is hard
|
17 | });
|
18 | ```
|
19 |
|
20 | ## Document
|
21 |
|
22 | Top-level result of `parseString`.
|
23 |
|
24 | ### Document.root
|
25 |
|
26 | The document-level Node of the XML Document
|
27 |
|
28 | ### Document.find(nodeName)
|
29 |
|
30 | Locate all nodes with named `nodeName`
|
31 |
|
32 | Returns an Array of all matching Nodes.
|
33 |
|
34 | Is an alias of `Document.root.find`.
|
35 |
|
36 | ## Node
|
37 |
|
38 | An element in the XML document.
|
39 |
|
40 | ### Node.name
|
41 |
|
42 | The name of the Node. e.g. <foo> would return "foo".
|
43 |
|
44 | ### Node.value
|
45 |
|
46 | A concatenated string of all the direct CDATA children of this Node.
|
47 |
|
48 | ### Node.parent
|
49 |
|
50 | This Node's parent Node. If this is the root Node, then `null`.
|
51 |
|
52 | ### Node.children
|
53 |
|
54 | An Array of the Node's children.
|
55 |
|
56 | ### Node.attrs
|
57 |
|
58 | An Object containing each of the Node's attributes as keys.
|
59 |
|
60 | ```js
|
61 | // <foo bar="baz">
|
62 | node.attrs.bar; // "baz"
|
63 | ```
|
64 |
|
65 | ### Node.find(nodeName)
|
66 |
|
67 | Locate all child Nodes named `nodeName`
|
68 |
|
69 | Returns an Array of all matching Nodes.
|
70 |
|
71 | ### Node.parents(nodeName)
|
72 |
|
73 | Locate all Nodes in the Node's parent tree named `nodeName`.
|