-
Notifications
You must be signed in to change notification settings - Fork 5
XMLParser
do- edited this page Nov 5, 2022
·
26 revisions
XMLParser is ...
const fs = require ('fs')
const {XMLParser} = require ('xml-toolkit')
const xml = fs.readFileSync ('doc.xml')
const parser = new XMLParser ({...options})
const doc = parser.process (xml)
console.log (doc.attributes)| Name | Default | Description |
|---|---|---|
| useEntities | true | If true, the EntityResolver is in use, otherwise &...; may occur in output |
| useNamespaces | true | If true, all element attributes are scanned for xmlns... prefixes |
| stripSpace |
true if filterElements is set, otherwise false
|
If true, text fragments are trimmed |
...
| Name, Params | Type | Description |
|---|---|---|
| src | String | XML to parse |
Return value: the XMLNode object representing the document element.
Sequences of text/CDATA fragments are concatenated together to atomic Characters nodes.
If useEntities option is set on (by default), Characters fragments are transformed by EntityResolver (CDATA never are).
To drop insignificant whitespace, use the stripSpace option. When it's set to true, every aggregated text fragment is trimmed down, emptied lines are ignored completely. So, for example, <foo/>\n\n<bar/> yields no Characters at all, but for a <![CDATA[cdata]]> section spaces are left in place.