Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,19 @@ interface Node {
attrs?: Record<string, string>;
}
```

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

```ts
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
12 changes: 12 additions & 0 deletions e2e/serialize.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const {parse, stringify, Node} = require('../dst/index');

describe('serialize', () => {
it('readme example', () => {
const root = parse('<!DOCTYPE html><html>hello</html>');

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

expect(stringify(root)).toEqual('<!DOCTYPE html><html>hello, world!</html>');
});
});
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Node, TYPES, VOID_ELEMENTS} from './node';
import {Node, TYPES} from './node';
import {Tokenizer} from './tokenizer';
import {stringifyAttrs} from './utils';

Expand Down