Appearance
Class: Expat
Defined in: expat/src/expat.ts:49
Expat XML parser WASM library, provides a simplified wrapper around the Expat XML Parser library.
See libexpat.github.io for c++ details.
ts
import { Expat } from "@hpcc-js/wasm-expat";
const expat = await Expat.load();
const xml = ` \
<root>
<child xxx="yyy">content</child>
</root>
`;
const callback = {
startElement(tag, attrs) { console.log("start", tag, attrs); },
endElement(tag) { console.log("end", tag); },
characterData(content) { console.log("characterData", content); }
};
expat.parse(xml, callback);
Methods
load()
static
load():Promise
<Expat
>
Defined in: expat/src/expat.ts:63
Compiles and instantiates the raw wasm.
INFO
In general WebAssembly compilation is disallowed on the main thread if the buffer size is larger than 4KB, hence forcing load
to be asynchronous;
Returns
Promise
<Expat
>
A promise to an instance of the Expat class.
unload()
static
unload():void
Defined in: expat/src/expat.ts:72
Unloades the compiled wasm instance.
Returns
void
version()
version():
string
Defined in: expat/src/expat.ts:80
Returns
string
The Expat c++ version
parse()
parse(
xml
,callback
):boolean
Defined in: expat/src/expat.ts:95
Parses the XML with suitable callbacks.
TIP
The IParser.characterData callback method can get called several times for a single tag element.
Parameters
xml
string
string containing XML
callback
Callback interface
Returns
boolean
true
|false
if the XML parse succeeds.