# xml-js-builder

> XML library to ease the use of XML with namespaces

Latest version **1.0.3** (published 2018-05-06) · Unlicense license · 0 weekly downloads

## Install

```sh
npm install xml-js-builder
pnpm add xml-js-builder
yarn add xml-js-builder
bun add xml-js-builder
```

## Health

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

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.3 |
| Published | 2018-05-06 |
| First published | 2017-07-15 |
| Weekly downloads | 0 |
| License | Unlicense |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >= 4 |
| Dependencies | 1 |
| Unpacked size | 18.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Adrien Castex |
| Maintainers | adriencastex |
| Keywords | xml, json, js, parser, builder, namespace |

## Links

- npm: https://www.npmjs.com/package/xml-js-builder
- Repository: https://github.com/OpenMarshal/xml-js-builder
- Homepage: https://github.com/OpenMarshal/xml-js-builder#readme
- Issues: https://github.com/OpenMarshal/xml-js-builder/issues
- npm.io page: https://npm.io/package/xml-js-builder

## Dependencies (1)

- [xml-js](https://npm.io/package/xml-js.md) ^1.6.2

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 1.0.3 (latest) — 2018-05-06
- 1.0.2 — 2018-05-06
- 1.0.1 — 2017-07-15
- 1.0.0 — 2017-07-15

## README

# xml-js-builder [![npm Version](https://img.shields.io/npm/v/xml-js-builder.svg)](https://www.npmjs.com/package/xml-js-builder) [![Build Status](https://travis-ci.org/OpenMarshal/xml-js-builder.svg?branch=master)](https://travis-ci.org/OpenMarshal/xml-js-builder)

This is a `npm` library which ease the use of XML with namespaces.

This way, parsing `<tag xmlns="ns"/>` will be reachable by `.find('ns:tag')` instead of having to check the attributes to know if it is in the right namespace.

The `xmljs.XML.parse(...)` can parse XML, JSON (compact and extended) from `xml-js`.

## Install

```bash
npm install xml-js-builder
```

## Usage

```javascript
const xmljs = require('xml-js-builder');

const xml = xmljs.XML.parse(myXML);

try
{
    const text = xml.find('DAV:tag').find('DAV:subtag').findText();
    const texts = xml.find('DAV:tag').findMany('DAV:subtags').map((tag) => tag.findText());

    // [...]
}
catch(ex)
{
    console.error(ex);
}
```

```javascript
const xmljs = require('xml-js-builder');

// <d:multistatus xmlns:d="DAV:" xmlns:x="ok:"> ... </d:multistatus>
const xml = new xmljs.XMLElementBuilder('d:multistatus', {
    'xmlns:d': 'DAV:',
    'xmlns:x': 'ok:'
});
// <d:deep xmlns="ttt:"><test/></d:deep>
xml.ele('d:deep', {
    'xmlns': 'ttt:'
}).ele('test');
// <d:node2>Ok1</d:node2>
xml.ele('d:node2').add('Ok1')
// <d:node2>Ok2</d:node2>
xml.ele('d:node2').add('Ok2')
// <d:tag/>
xml.ele('d:tag')
// <x:test/>
xml.ele('x:test')
// <d:nons>yes</d:nons>
xml.ele('nons').add('yes')
// <d:node2>Ok3</d:node2>
xml.ele('d:node2').add('Ok3')

console.log(xml.toJSON());
console.log(xml.toXML());
```

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