# xml.js

> XML.js provides helper functions for XML manipulation, including conversion of documents into [JXON](https://developer.mozilla.org/en-US/docs/JXON) objects. It is built on top of [xmldom](https://www.npmjs.org/package/xmldom) & [xpath](https://www.npmjs.o

Latest version **0.0.8** (published 2014-11-13) · 0 weekly downloads

## Install

```sh
npm install xml.js
pnpm add xml.js
yarn add xml.js
bun add xml.js
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.8 |
| Published | 2014-11-13 |
| First published | 2014-10-14 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Known vulnerabilities | 0 (+16 in 1 direct dependencies) |
| Install scripts | no |
| Maintainers | pvoisin |
| Keywords | XML, JXON, DOM |

## Links

- npm: https://www.npmjs.com/package/xml.js
- Repository: https://github.com/pvoisin/xml.js
- Issues: https://github.com/pvoisin/xml.js/issues
- npm.io page: https://npm.io/package/xml.js

## Dependencies (3)

- [xpath](https://npm.io/package/xpath.md) 0.0.7
- [xmldom](https://npm.io/package/xmldom.md) ~0.1.19
- [ytility](https://npm.io/package/ytility.md) 0.0.2

## Alternatives

- [babylon](https://npm.io/package/babylon.md) — 5.1M weekly downloads
- [csscolorparser](https://npm.io/package/csscolorparser.md) — 3.7M weekly downloads
- [expr-eval-fork](https://npm.io/package/expr-eval-fork.md) — 1.5M weekly downloads
- [@leeoniya/ufuzzy](https://npm.io/package/@leeoniya/ufuzzy.md) — 247.7K weekly downloads
- [xml-parser](https://npm.io/package/xml-parser.md) — 78.4K weekly downloads

## Recent versions

- 0.0.8 (latest) — 2014-11-13
- 0.0.7 — 2014-10-18
- 0.0.6 — 2014-10-18
- 0.0.5 — 2014-10-18
- 0.0.4 — 2014-10-14
- 0.0.3 — 2014-10-14
- 0.0.2 — 2014-10-14

## README

# XML.js
## What for?
XML.js provides helper functions for XML manipulation, including conversion of documents into [JXON](https://developer.mozilla.org/en-US/docs/JXON) objects.
It is built on top of [xmldom](https://www.npmjs.org/package/xmldom) & [xpath](https://www.npmjs.org/package/xpath) modules and brings common XML-related features together into a simplistic API.

## API

### XML#parse
```javascript
function parse(text) { ... //-> DOMDocument
```

### XML#load
```javascript
function load(file, [convert:false]) { ... //-> DOMDocument
```

### XML#serialize
```javascript
function serialize(node) { ... //-> String
```

### XML#query
```javascript
function query(node, expression, resolver) { ... //-> [Node]
```

####Example
```javascript
XML.query(catalog, "//book[1]");
XML.query(response, "//here:contact[1]",  {"here": "http://being.here/"});
```



## JXON

### convert
```javascript
function convert(node, [compact:true]) { ... //-> {Object}
```

####Example
Given `document` is the following:
```xml
<contact firstName="George" lastName="Cartier">
    <notes>
        <![CDATA[
            Will call back tomorrow.
        ]]>
    </notes>
</contact>
```
Resulting JXON object, converted with `JXON.convert(document)`, would be:
<a name="JXON_convert_result"></a>
```javascript
{
	"contact": {
		"firstName": "George",
		"lastName": "Cartier",
		"*": {
			"notes": {
				"*": {
					"#D": "Will call back tomorrow."
				}
			}
		}
	}
}
```

### compact
```javascript
function compact(object) { ... //-> {Object}
```
####Example
When not compacted, [previous result](#JXON_convert_result) would be the following, which could be compacted afterwards with `JXON#compact`:
```javascript
{
	"contact": {
		"@firstName": "George",
		"@lastName": "Cartier",
		"children": [
			{
				"#TEXT": "\n            "
			},
			{
				"notes": {
					"children": [
						{
							"#TEXT": "\n                "
						},
						{
							"#CDATA": "\n                    Will call back tomorrow.\n                "
						},
						{
							"#TEXT": "\n            "
						}
					]
				}
			},
			{
				"#TEXT": "\n        "
			}
		]
	}
}
```

## More?

Please have a look to the test [fixtures](test/fixtures)!

---
_Source: https://npm.io/package/xml.js · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
