Is a fast XML parser in TypeScript with zero dependencies
- blazing fast โก
- zero dependencies ๐ฆ
import {parse} from 'fast-xml-parser';
// Node { name: 'root', children: [
// Node { name: 'html', children: [...]
// }] }
const root = parse('<!DOCTYPE html><html>hello</html>');
Parse
returns a Node
object, the root of the document tree. Node
is an object with the following interface:
interface Node {
type: TYPES;
name: string;
children?: Node[];
attrs?: Record<string, string>;
}
You can manipulate the tree and serialize it back to HTML:
import {parse, stringify} from 'fast-xml-parser';
const root = parse('<!DOCTYPE html><html>hello</html>');
// change text node
root.children[1].children[0].name = 'hello, world!'
// <!DOCTYPE html><html>hello, world!</html>
console.log(stringify(root));
TBD: DOM API to manipulate the tree in a handy way