Appearance
Class: Expat
expat.Expat
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
▸ load(): Promise
<Expat
>
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.
Defined in
unload
▸ unload(): void
Unloades the compiled wasm instance.
Returns
void
Defined in
version
▸ version(): string
Returns
string
The Expat c++ version
Defined in
parse
▸ parse(xml
, callback
): boolean
Parses the XML with suitable callbacks.
TIP
The IParser.characterData callback method can get called several times for a single tag element.
Parameters
Name | Type | Description |
---|---|---|
xml | string | string containing XML |
callback | IParser | Callback interface |
Returns
boolean
true
|false
if the XML parse succeeds.