https://github.com/potch/xmlom
Basic XML Object Model
https://github.com/potch/xmlom
Last synced: 4 months ago
JSON representation
Basic XML Object Model
- Host: GitHub
- URL: https://github.com/potch/xmlom
- Owner: potch
- Created: 2015-06-30T18:30:47.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2020-11-07T22:54:18.000Z (over 5 years ago)
- Last Synced: 2025-08-16T10:59:07.600Z (10 months ago)
- Language: JavaScript
- Homepage:
- Size: 861 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# xmlom - a tiny XML object model
[](https://greenkeeper.io/)
## Usage
### `xmlom.parseString(str)`
Parse an XML String.
Returns a Promise which resolves to a Document.
```js
var xmlom = require('xmlom');
xmlom.parseString('bar').then(function (doc) {
doc.find('foo').value; // "bar"
}).catch(function (error) {
// parsing is hard
});
```
## Document
Top-level result of `parseString`.
### Document.root
The document-level Node of the XML Document
### Document.find(nodeName)
Locate all nodes with named `nodeName`
Returns an Array of all matching Nodes.
Is an alias of `Document.root.find`.
## Node
An element in the XML document.
### Node.name
The name of the Node. e.g. <foo> would return "foo".
### Node.value
A concatenated string of all the direct CDATA children of this Node.
### Node.parent
This Node's parent Node. If this is the root Node, then `null`.
### Node.children
An Array of the Node's children.
### Node.attrs
An Object containing each of the Node's attributes as keys.
```js
//
node.attrs.bar; // "baz"
```
### Node.comment
The text of any commments directly preceding the Node:
```js
/*
bar */
node.comment; // "This is a comment"
```
### Node.find(nodeName)
Locate all child Nodes named `nodeName`
Returns an Array of all matching Nodes.
### Node.parents(nodeName)
Locate all Nodes in the Node's parent tree named `nodeName`.