Skip to content

API Reference Overview

The public package is a pure JavaScript StAX-style parser and writer.

Recommendation: use the converter API first when the target XML-to-object shape is known. If you need a low-overhead StAX core, start with StreamReader or StreamReaderSync; on large synchronous byte input, consume each batch with eventCount plus index accessors. If you want ergonomic event objects, use EventReader or EventReaderSync.

SurfaceImport pathPurposeImplementation notes
StreamReaderstax-xmlAsync batch-first StAX core for ReadableStream<Uint8Array>.Uses the JavaScript byte reader and yields StreamBatch views.
StreamReaderSyncstax-xmlSync batch-first StAX core for Uint8Array or byte-batch iterables.Uses the JavaScript byte reader. eventCount is batch-local, and views are invalidated by the next nextBatch() call.
EventReaderstax-xmlAsync event reader for ReadableStream<Uint8Array> input.Preserves stream backpressure at the public boundary.
EventReaderSyncstax-xmlSync event reader for an in-memory XML string.Materializes AnyXmlEvent values from the JavaScript reader stack.
Writerstax-xmlAsync writer for WritableStream<Uint8Array>.Emits encoded XML incrementally to a web writable stream.
WriterSyncstax-xmlIn-memory synchronous writer.Builds and returns the XML string; the package default export remains WriterSync.
WriterSyncSinkstax-xmlSynchronous sink writer for large output.Writes incrementally to a SyncTextSink instead of retaining the full XML string.
Tree/object helpersstax-xmlparseXmlTree*() and parseXmlObject*() convenience APIs.Project unknown XML into an order-preserving tree or compact object using the same reader stack.

The package does not expose native, Wasm, or backend-selection modes. The public contract is pure JavaScript and the boundary cost of returning JavaScript strings and objects is part of the measured workload.

The main types exported by StAX-XML are:

  • XmlEventType - Enumeration of XML event types
  • AnyXmlEvent - Union type of all XML events
  • StartElementEvent - Start element events with attributes
  • CharactersEvent - Text content events
  • ErrorEvent - Parsing error events
  • XmlAttribute - XML attribute interface
  • XmlTreeDocument / XmlTreeElement - Order-preserving tree helper result types
  • XmlObjectRecord / XmlObjectValue - Compact object helper result types
  • ParseXmlTreeOptions / ParseXmlObjectOptions - Tree/object helper options
  • SyncTextSink - Custom synchronous sink target for WriterSyncSink
  • EventReaderOptions / EventReaderSyncOptions - Event reader options
  • WriterOptions / WriterSyncOptions - Async and sync writer options
  • WriterSyncSinkOptions - Sink-based sync writer options

For detailed type information and method signatures, please refer to the individual API guides above.