UNPKG

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