Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/vitkarpov/fast-xml-parser

🚀 Is a fast XML parser in TypeScript with zero dependencies
https://github.com/vitkarpov/fast-xml-parser

dom html-parser html-parser-library javascript typescript

Last synced: 3 months ago
JSON representation

🚀 Is a fast XML parser in TypeScript with zero dependencies

Awesome Lists containing this project

README

        

# 🚀 Fast-XML-parser

> Is a fast XML parser in TypeScript with zero dependencies

[![CircleCI](https://circleci.com/gh/vitkarpov/fast-xml-parser.svg?style=svg)](https://circleci.com/gh/vitkarpov/fast-xml-parser)
[![Code Style: Google](https://img.shields.io/badge/code%20style-google-blueviolet.svg)](https://github.com/google/gts)

- blazing fast âš¡
- zero dependencies 📦

## Talk is cheap show me the code, or API overview

```ts
import {parse} from 'fast-xml-parser';

// Node { name: 'root', children: [
// Node { name: 'html', children: [...]
// }] }
const root = parse('hello');
```

`Parse` returns a `Node` object, the root of the document tree. `Node` is an object with the following interface:

```ts
interface Node {
type: TYPES;
name: string;
children?: Node[];
attrs?: Record;
}
```

You can manipulate the tree and serialize it back to HTML:

```ts
import {parse, stringify} from 'fast-xml-parser';

const root = parse('hello');

// change text node
root.children[1].children[0].name = 'hello, world!'

// hello, world!
console.log(stringify(root));
```

> TBD: DOM API to manipulate the tree in a handy way