Parse a XML string into a proprietary syntax tree
npm install xml-parser-xoAn XML parser based on xml-parser.
 
```
$ npm install xml-parser-xo
`js
import xmlParser from 'xml-parser-xo';
var xml = ;
xmlParser(xml);
`
`json`
{
"declaration": {
"type": "ProcessingInstruction",
"attributes": {"version": "1.0", "encoding": "utf-8"}
},
"root": {
"type": "Element",
"name": "foo",
"attributes": {},
"children": [
{"type": "CDATA", "content": ""},
{"type": "Text", "content": " content"}
]
},
"children": [
{"type": "Comment", "content": ""},
{"type": "ProcessingInstruction", "attributes": {"href": "foo.xsl", "type": "text/xsl"}},
{"type": "DocumentType", "content": ""},
{
"type": "Element",
"name": "foo",
"attributes": {},
"children": [
{"type": "CDATA", "content": ""},
{"type": "Text", "content": " content"}
]
}
]
}
- filter: Function to filter out unwanted nodes by returning false.function(node) => boolean
- type: () => true
- default: strictMode
- : True to throw an error when parsing XML document with invalid content like mismatched closing tags.boolean
- type: false
- default:
`js
import xmlParser from 'xml-parser-xo';
const xml = ;
xmlParser(xml, {
filter: (node) => {
return node.type === 'Element' || node.type === 'Text';
}
});
`
`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"}
]
}
]
}
MIT