Skip to content

@hpcc-js/wasmDocs


Class: 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()

static 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

expat.ts:63


unload()

static unload(): void

Unloades the compiled wasm instance.

Returns

void

Defined in

expat.ts:72


version()

version(): string

Returns

string

The Expat c++ version

Defined in

expat.ts:80


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

xml: string

string containing XML

callback: IParser

Callback interface

Returns

boolean

true|false if the XML parse succeeds.

Defined in

expat.ts:95

Released under the Apache-2.0 License.