# xml-parser-xo

> Parse a XML string into a proprietary syntax tree

Latest version **4.1.6** (published 2026-05-21) · MIT license · 0 weekly downloads

## Install

```sh
npm install xml-parser-xo
pnpm add xml-parser-xo
yarn add xml-parser-xo
bun add xml-parser-xo
```

## Health

**Score 65/100 (B)** — status: active.

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

Warnings: low downloads; no esm support.

## Facts

| | |
|---|---|
| Version | 4.1.6 |
| Published | 2026-05-21 |
| First published | 2016-11-14 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >= 20 |
| Dependencies | 0 |
| Unpacked size | 42.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 5 |
| Author | Chris Bottin |
| Maintainers | chrisbottin |
| Keywords | xml, parse, parser, convert, converter, syntax, tree |

## Links

- npm: https://www.npmjs.com/package/xml-parser-xo
- Repository: https://github.com/chrisbottin/xml-parser
- Homepage: https://github.com/chrisbottin/xml-parser#readme
- Issues: https://github.com/chrisbottin/xml-parser/issues
- npm.io page: https://npm.io/package/xml-parser-xo

## 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

- 4.1.6 (latest) — 2026-05-21
- 4.1.5 — 2025-09-18
- 4.1.4 — 2025-05-11
- 4.1.3 — 2024-12-12
- 4.1.2 — 2024-07-07
- 4.1.1 — 2023-07-04
- 4.1.0 — 2023-05-15
- 4.0.5 — 2023-03-07
- 4.0.4 — 2023-02-22
- 4.0.3 — 2023-02-21
- 4.0.2 — 2023-02-10
- 4.0.1 — 2022-12-17
- 4.0.0 — 2022-12-13
- 3.2.0 — 2021-12-21
- 3.1.2 — 2021-09-13
- … 9 more at https://npm.io/package/xml-parser-xo/versions

## README

# xml-parser-xo

An XML parser based on [xml-parser](https://www.npmjs.com/package/xml-parser).

[![Build Status](https://github.com/chrisbottin/xml-parser/actions/workflows/ci.yml/badge.svg)](https://github.com/chrisbottin/xml-parser/actions/workflows/ci.yml) [![npm version](https://img.shields.io/npm/v/xml-parser-xo.svg)](https://npmjs.org/package/xml-parser-xo)

## Installation

```
$ npm install xml-parser-xo
```

## Example

### Usage:

```js
import xmlParser from 'xml-parser-xo';

var xml = `<?xml version="1.0" encoding="utf-8"?>
<!-- Load the stylesheet -->
<?xml-stylesheet href="foo.xsl" type="text/xsl" ?>
<!DOCTYPE foo SYSTEM "foo.dtd">
<foo><![CDATA[some text]]> content</foo>`;

xmlParser(xml);
```

### Output:

```json
{
    "declaration": {
        "type": "ProcessingInstruction",
        "attributes": {"version": "1.0", "encoding": "utf-8"}
    },
    "root": {
        "type": "Element",
        "name": "foo",
        "attributes": {},
        "children": [
            {"type": "CDATA", "content": "<![CDATA[some text]]>"},
            {"type": "Text", "content": " content"}
        ]
    },
    "children": [
        {"type": "Comment", "content": "<!-- Load the stylesheet -->"},
        {"type": "ProcessingInstruction", "attributes": {"href": "foo.xsl", "type": "text/xsl"}},
        {"type": "DocumentType", "content": "<!DOCTYPE foo SYSTEM \"foo.dtd\">"},
        {
            "type": "Element",
            "name": "foo",
            "attributes": {},
            "children": [
                {"type": "CDATA", "content": "<![CDATA[some text]]>"},
                {"type": "Text", "content": " content"}
            ]
        }
    ]
}
```

## Options

- `filter`: Function to filter out unwanted nodes by returning `false`.
  - type: `function(node) => boolean`
  - default: `() => true`
- `strictMode`: True to throw an error when parsing XML document with invalid content like mismatched closing tags.
  - type: `boolean`
  - default: `false`

### Usage:

```js
import xmlParser from 'xml-parser-xo';

const xml = `<?xml version="1.0" encoding="utf-8"?>
<!-- Load the stylesheet -->
<?xml-stylesheet href="foo.xsl" type="text/xsl" ?>
<!DOCTYPE foo SYSTEM "foo.dtd">
<foo><![CDATA[some text]]> content</foo>`;

xmlParser(xml, {
    filter: (node) => {
        return node.type === 'Element' || node.type === 'Text';
    }
});
```

### Output:

```json
{
    "declaration": {
        "type": "ProcessingInstruction",
        "attributes": {"version": "1.0", "encoding": "utf-8"}
    },
    "root": {
        "type": "Element",
        "name": "foo",
        "attributes": {},
        "children": [
            {"type": "Text", "content": " content"}
        ]
    },
    "children": [
        {
            "type": "Element",
            "name": "foo",
            "attributes": {},
            "children": [
                {"type": "Text", "content": " content"}
            ]
        }
    ]
}
```

## License

MIT

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