stax-xml
stax-xml
stax-xml
Section titled “stax-xml”Declarative XML Converter Module
Remarks
Section titled “Remarks”This module provides a zod-style declarative API for parsing XML documents. It allows you to define XML schemas using a fluent API and parse XML with XPath support.
Example
Section titled “Example”Basic usage:
import { x } from 'stax-xml/converter';
const schema = x.object({ title: x.string().xpath('/book/title'), author: x.string().xpath('/book/author'), price: x.number().xpath('/book/price')});
const xml = '<book><title>TypeScript</title><author>John</author><price>29.99</price></book>';const result = await schema.parse(xml);// { title: 'TypeScript', author: 'John', price: 29.99 }Classes
Section titled “Classes”Writer
Section titled “Writer”Defined in: Writer.ts:131
High-performance asynchronous XML writer implementing the StAX (Streaming API for XML) pattern.
This writer provides efficient streaming XML generation using WritableStream for handling large XML documents with automatic buffering, backpressure management, and namespace support.
This is an optimized implementation with:
- Optimization 1: Regex caching for entity escaping
- Optimization 2: Attribute string batching
- Optimization 3: Early entity check before regex execution
- Optimization 4: Qualified closing-tag stack (avoid rebuilding end tags)
- Optimization 5: Copy-on-write namespace frames
- Optimization 6: Indentation cache for pretty-print output
- Optimization 7:
TextEncoder.encodeInto()buffering to reduce intermediate byte arrays - Optimization 8: Flush by buffer view to avoid per-flush copy slices
Remarks
Section titled “Remarks”The writer supports streaming output with configurable buffering, automatic entity encoding, pretty printing with customizable indentation, and comprehensive namespace handling.
Examples
Section titled “Examples”Basic usage:
const writableStream = new WritableStream({ write(chunk) { console.log(new TextDecoder().decode(chunk)); }});
const writer = new Writer(writableStream);await writer.writeStartElement('root');await writer.writeElement('item', { id: '1' }, 'Hello World');await writer.writeEndElement();await writer.close();With pretty printing:
const options = { prettyPrint: true, indentString: ' ', autoEncodeEntities: true};const writer = new Writer(writableStream, options);Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new Writer(
stream,options?):Writer
Defined in: Writer.ts:170
Parameters
Section titled “Parameters”stream
Section titled “stream”WritableStream<Uint8Array<ArrayBufferLike>>
options?
Section titled “options?”WriterOptions = {}
Returns
Section titled “Returns”Methods
Section titled “Methods”writeStartDocument()
Section titled “writeStartDocument()”writeStartDocument(
version?,encoding?):Promise<Writer>
Defined in: Writer.ts:292
Write XML declaration
Parameters
Section titled “Parameters”version?
Section titled “version?”string = '1.0'
encoding?
Section titled “encoding?”string
Returns
Section titled “Returns”Promise<Writer>
writeEndDocument()
Section titled “writeEndDocument()”writeEndDocument():
Promise<void>
Defined in: Writer.ts:317
End document (automatically close all elements)
Returns
Section titled “Returns”Promise<void>
writeStartElement()
Section titled “writeStartElement()”writeStartElement(
localName,options?):Promise<Writer>
Defined in: Writer.ts:338
Write start element
Parameters
Section titled “Parameters”localName
Section titled “localName”string
options?
Section titled “options?”Returns
Section titled “Returns”Promise<Writer>
writeEndElement()
Section titled “writeEndElement()”writeEndElement():
Promise<Writer>
Defined in: Writer.ts:430
Write end element
Returns
Section titled “Returns”Promise<Writer>
writeCharacters()
Section titled “writeCharacters()”writeCharacters(
text):Promise<Writer>
Defined in: Writer.ts:463
Write text
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”Promise<Writer>
writeCData()
Section titled “writeCData()”writeCData(
cdata):Promise<Writer>
Defined in: Writer.ts:485
Write CDATA section
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”Promise<Writer>
writeComment()
Section titled “writeComment()”writeComment(
comment):Promise<Writer>
Defined in: Writer.ts:505
Write comment
Parameters
Section titled “Parameters”comment
Section titled “comment”string
Returns
Section titled “Returns”Promise<Writer>
writeRaw()
Section titled “writeRaw()”writeRaw(
xml):Promise<Writer>
Defined in: Writer.ts:528
Write raw XML content without escaping
Parameters
Section titled “Parameters”string
Raw XML string to write
Returns
Section titled “Returns”Promise<Writer>
this (chainable)
flush()
Section titled “flush()”flush():
Promise<void>
Defined in: Writer.ts:537
Manual flush
Returns
Section titled “Returns”Promise<void>
getMetrics()
Section titled “getMetrics()”getMetrics():
object
Defined in: Writer.ts:544
Return metrics
Returns
Section titled “Returns”object
totalBytesWritten
Section titled “totalBytesWritten”totalBytesWritten:
number=0
flushCount
Section titled “flushCount”flushCount:
number=0
lastFlushTime
Section titled “lastFlushTime”lastFlushTime:
number=0
bufferUtilization
Section titled “bufferUtilization”bufferUtilization:
number
averageFlushSize
Section titled “averageFlushSize”averageFlushSize:
number
WriterSync
Section titled “WriterSync”Defined in: WriterSync.ts:493
String-based sync writer.
Extends
Section titled “Extends”AbstractWriterSync
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new WriterSync(
options?):WriterSync
Defined in: WriterSync.ts:496
Parameters
Section titled “Parameters”options?
Section titled “options?”WriterSyncOptions = {}
Returns
Section titled “Returns”Overrides
Section titled “Overrides”AbstractWriterSync.constructor
Properties
Section titled “Properties”
protectedstate:number=WriterState.INITIAL
Defined in: WriterSync.ts:78
Inherited from
Section titled “Inherited from”AbstractWriterSync.state
elementStack
Section titled “elementStack”
protectedelementStack:string[] =[]
Defined in: WriterSync.ts:79
Inherited from
Section titled “Inherited from”AbstractWriterSync.elementStack
hasTextContentStack
Section titled “hasTextContentStack”
protectedhasTextContentStack:boolean[] =[]
Defined in: WriterSync.ts:80
Inherited from
Section titled “Inherited from”AbstractWriterSync.hasTextContentStack
namespaceStack
Section titled “namespaceStack”
protectednamespaceStack:Map<string,string>[] =[]
Defined in: WriterSync.ts:81
Inherited from
Section titled “Inherited from”AbstractWriterSync.namespaceStack
namespaceOwnedStack
Section titled “namespaceOwnedStack”
protectednamespaceOwnedStack:boolean[] =[]
Defined in: WriterSync.ts:82
Inherited from
Section titled “Inherited from”AbstractWriterSync.namespaceOwnedStack
options
Section titled “options”
protectedreadonlyoptions:Required<WriterSyncOptions>
Defined in: WriterSync.ts:83
Inherited from
Section titled “Inherited from”AbstractWriterSync.options
currentIndentLevel
Section titled “currentIndentLevel”
protectedcurrentIndentLevel:number=0
Defined in: WriterSync.ts:84
Inherited from
Section titled “Inherited from”AbstractWriterSync.currentIndentLevel
needsIndent
Section titled “needsIndent”
protectedneedsIndent:boolean=false
Defined in: WriterSync.ts:85
Inherited from
Section titled “Inherited from”AbstractWriterSync.needsIndent
indentCache
Section titled “indentCache”
protectedindentCache:string[]
Defined in: WriterSync.ts:86
Inherited from
Section titled “Inherited from”AbstractWriterSync.indentCache
Methods
Section titled “Methods”writeStartDocument()
Section titled “writeStartDocument()”writeStartDocument(
version?,encoding?):this
Defined in: WriterSync.ts:133
Writes the XML declaration (e.g., ).
Parameters
Section titled “Parameters”version?
Section titled “version?”string = '1.0'
encoding?
Section titled “encoding?”string
Returns
Section titled “Returns”this
Inherited from
Section titled “Inherited from”AbstractWriterSync.writeStartDocument
writeEndDocument()
Section titled “writeEndDocument()”writeEndDocument():
void
Defined in: WriterSync.ts:158
Indicates the end of the document and automatically closes all open elements.
Returns
Section titled “Returns”void
Inherited from
Section titled “Inherited from”AbstractWriterSync.writeEndDocument
writeStartElement()
Section titled “writeStartElement()”writeStartElement(
localName,options?):this
Defined in: WriterSync.ts:170
Parameters
Section titled “Parameters”localName
Section titled “localName”string
options?
Section titled “options?”Returns
Section titled “Returns”this
Inherited from
Section titled “Inherited from”AbstractWriterSync.writeStartElement
writeAttribute()
Section titled “writeAttribute()”writeAttribute(
localName,value,prefix?):this
Defined in: WriterSync.ts:249
Parameters
Section titled “Parameters”localName
Section titled “localName”string
string
prefix?
Section titled “prefix?”string
Returns
Section titled “Returns”this
Inherited from
Section titled “Inherited from”AbstractWriterSync.writeAttribute
writeNamespace()
Section titled “writeNamespace()”writeNamespace(
prefix,uri):this
Defined in: WriterSync.ts:259
Parameters
Section titled “Parameters”prefix
Section titled “prefix”string
string
Returns
Section titled “Returns”this
Inherited from
Section titled “Inherited from”AbstractWriterSync.writeNamespace
writeCharacters()
Section titled “writeCharacters()”writeCharacters(
text):this
Defined in: WriterSync.ts:276
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”this
Inherited from
Section titled “Inherited from”AbstractWriterSync.writeCharacters
writeCData()
Section titled “writeCData()”writeCData(
cdata):this
Defined in: WriterSync.ts:290
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”this
Inherited from
Section titled “Inherited from”AbstractWriterSync.writeCData
writeComment()
Section titled “writeComment()”writeComment(
comment):this
Defined in: WriterSync.ts:307
Parameters
Section titled “Parameters”comment
Section titled “comment”string
Returns
Section titled “Returns”this
Inherited from
Section titled “Inherited from”AbstractWriterSync.writeComment
writeProcessingInstruction()
Section titled “writeProcessingInstruction()”writeProcessingInstruction(
target,data?):this
Defined in: WriterSync.ts:322
Parameters
Section titled “Parameters”target
Section titled “target”string
string
Returns
Section titled “Returns”this
Inherited from
Section titled “Inherited from”AbstractWriterSync.writeProcessingInstruction
writeRaw()
Section titled “writeRaw()”writeRaw(
xml):this
Defined in: WriterSync.ts:344
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”this
Inherited from
Section titled “Inherited from”AbstractWriterSync.writeRaw
writeEndElement()
Section titled “writeEndElement()”writeEndElement():
this
Defined in: WriterSync.ts:350
Returns
Section titled “Returns”this
Inherited from
Section titled “Inherited from”AbstractWriterSync.writeEndElement
setPrettyPrint()
Section titled “setPrettyPrint()”setPrettyPrint(
enabled):this
Defined in: WriterSync.ts:382
Parameters
Section titled “Parameters”enabled
Section titled “enabled”boolean
Returns
Section titled “Returns”this
Inherited from
Section titled “Inherited from”AbstractWriterSync.setPrettyPrint
setIndentString()
Section titled “setIndentString()”setIndentString(
indentString):this
Defined in: WriterSync.ts:387
Parameters
Section titled “Parameters”indentString
Section titled “indentString”string
Returns
Section titled “Returns”this
Inherited from
Section titled “Inherited from”AbstractWriterSync.setIndentString
isPrettyPrintEnabled()
Section titled “isPrettyPrintEnabled()”isPrettyPrintEnabled():
boolean
Defined in: WriterSync.ts:393
Returns
Section titled “Returns”boolean
Inherited from
Section titled “Inherited from”AbstractWriterSync.isPrettyPrintEnabled
getIndentString()
Section titled “getIndentString()”getIndentString():
string
Defined in: WriterSync.ts:397
Returns
Section titled “Returns”string
Inherited from
Section titled “Inherited from”AbstractWriterSync.getIndentString
_closeStartElementTag()
Section titled “_closeStartElementTag()”
protected_closeStartElementTag():void
Defined in: WriterSync.ts:419
Returns
Section titled “Returns”void
Inherited from
Section titled “Inherited from”AbstractWriterSync._closeStartElementTag
_writeNewline()
Section titled “_writeNewline()”
protected_writeNewline():void
Defined in: WriterSync.ts:437
Returns
Section titled “Returns”void
Inherited from
Section titled “Inherited from”AbstractWriterSync._writeNewline
getXmlString()
Section titled “getXmlString()”getXmlString():
string
Defined in: WriterSync.ts:500
Returns
Section titled “Returns”string
_emit()
Section titled “_emit()”
protected_emit(chunk):void
Defined in: WriterSync.ts:504
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”void
Overrides
Section titled “Overrides”AbstractWriterSync._emit
WriterSyncSink
Section titled “WriterSyncSink”Defined in: WriterSync.ts:512
Sink-based sync writer. Use this for file/buffer incremental writes.
Extends
Section titled “Extends”AbstractWriterSync
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new WriterSyncSink(
sink,options?):WriterSyncSink
Defined in: WriterSync.ts:520
Parameters
Section titled “Parameters”options?
Section titled “options?”Returns
Section titled “Returns”Overrides
Section titled “Overrides”AbstractWriterSync.constructor
Properties
Section titled “Properties”
protectedstate:number=WriterState.INITIAL
Defined in: WriterSync.ts:78
Inherited from
Section titled “Inherited from”AbstractWriterSync.state
elementStack
Section titled “elementStack”
protectedelementStack:string[] =[]
Defined in: WriterSync.ts:79
Inherited from
Section titled “Inherited from”AbstractWriterSync.elementStack
hasTextContentStack
Section titled “hasTextContentStack”
protectedhasTextContentStack:boolean[] =[]
Defined in: WriterSync.ts:80
Inherited from
Section titled “Inherited from”AbstractWriterSync.hasTextContentStack
namespaceStack
Section titled “namespaceStack”
protectednamespaceStack:Map<string,string>[] =[]
Defined in: WriterSync.ts:81
Inherited from
Section titled “Inherited from”AbstractWriterSync.namespaceStack
namespaceOwnedStack
Section titled “namespaceOwnedStack”
protectednamespaceOwnedStack:boolean[] =[]
Defined in: WriterSync.ts:82
Inherited from
Section titled “Inherited from”AbstractWriterSync.namespaceOwnedStack
options
Section titled “options”
protectedreadonlyoptions:Required<WriterSyncOptions>
Defined in: WriterSync.ts:83
Inherited from
Section titled “Inherited from”AbstractWriterSync.options
currentIndentLevel
Section titled “currentIndentLevel”
protectedcurrentIndentLevel:number=0
Defined in: WriterSync.ts:84
Inherited from
Section titled “Inherited from”AbstractWriterSync.currentIndentLevel
needsIndent
Section titled “needsIndent”
protectedneedsIndent:boolean=false
Defined in: WriterSync.ts:85
Inherited from
Section titled “Inherited from”AbstractWriterSync.needsIndent
indentCache
Section titled “indentCache”
protectedindentCache:string[]
Defined in: WriterSync.ts:86
Inherited from
Section titled “Inherited from”AbstractWriterSync.indentCache
Methods
Section titled “Methods”writeStartDocument()
Section titled “writeStartDocument()”writeStartDocument(
version?,encoding?):this
Defined in: WriterSync.ts:133
Writes the XML declaration (e.g., ).
Parameters
Section titled “Parameters”version?
Section titled “version?”string = '1.0'
encoding?
Section titled “encoding?”string
Returns
Section titled “Returns”this
Inherited from
Section titled “Inherited from”AbstractWriterSync.writeStartDocument
writeStartElement()
Section titled “writeStartElement()”writeStartElement(
localName,options?):this
Defined in: WriterSync.ts:170
Parameters
Section titled “Parameters”localName
Section titled “localName”string
options?
Section titled “options?”Returns
Section titled “Returns”this
Inherited from
Section titled “Inherited from”AbstractWriterSync.writeStartElement
writeAttribute()
Section titled “writeAttribute()”writeAttribute(
localName,value,prefix?):this
Defined in: WriterSync.ts:249
Parameters
Section titled “Parameters”localName
Section titled “localName”string
string
prefix?
Section titled “prefix?”string
Returns
Section titled “Returns”this
Inherited from
Section titled “Inherited from”AbstractWriterSync.writeAttribute
writeNamespace()
Section titled “writeNamespace()”writeNamespace(
prefix,uri):this
Defined in: WriterSync.ts:259
Parameters
Section titled “Parameters”prefix
Section titled “prefix”string
string
Returns
Section titled “Returns”this
Inherited from
Section titled “Inherited from”AbstractWriterSync.writeNamespace
writeCharacters()
Section titled “writeCharacters()”writeCharacters(
text):this
Defined in: WriterSync.ts:276
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”this
Inherited from
Section titled “Inherited from”AbstractWriterSync.writeCharacters
writeCData()
Section titled “writeCData()”writeCData(
cdata):this
Defined in: WriterSync.ts:290
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”this
Inherited from
Section titled “Inherited from”AbstractWriterSync.writeCData
writeComment()
Section titled “writeComment()”writeComment(
comment):this
Defined in: WriterSync.ts:307
Parameters
Section titled “Parameters”comment
Section titled “comment”string
Returns
Section titled “Returns”this
Inherited from
Section titled “Inherited from”AbstractWriterSync.writeComment
writeProcessingInstruction()
Section titled “writeProcessingInstruction()”writeProcessingInstruction(
target,data?):this
Defined in: WriterSync.ts:322
Parameters
Section titled “Parameters”target
Section titled “target”string
string
Returns
Section titled “Returns”this
Inherited from
Section titled “Inherited from”AbstractWriterSync.writeProcessingInstruction
writeRaw()
Section titled “writeRaw()”writeRaw(
xml):this
Defined in: WriterSync.ts:344
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”this
Inherited from
Section titled “Inherited from”AbstractWriterSync.writeRaw
writeEndElement()
Section titled “writeEndElement()”writeEndElement():
this
Defined in: WriterSync.ts:350
Returns
Section titled “Returns”this
Inherited from
Section titled “Inherited from”AbstractWriterSync.writeEndElement
setPrettyPrint()
Section titled “setPrettyPrint()”setPrettyPrint(
enabled):this
Defined in: WriterSync.ts:382
Parameters
Section titled “Parameters”enabled
Section titled “enabled”boolean
Returns
Section titled “Returns”this
Inherited from
Section titled “Inherited from”AbstractWriterSync.setPrettyPrint
setIndentString()
Section titled “setIndentString()”setIndentString(
indentString):this
Defined in: WriterSync.ts:387
Parameters
Section titled “Parameters”indentString
Section titled “indentString”string
Returns
Section titled “Returns”this
Inherited from
Section titled “Inherited from”AbstractWriterSync.setIndentString
isPrettyPrintEnabled()
Section titled “isPrettyPrintEnabled()”isPrettyPrintEnabled():
boolean
Defined in: WriterSync.ts:393
Returns
Section titled “Returns”boolean
Inherited from
Section titled “Inherited from”AbstractWriterSync.isPrettyPrintEnabled
getIndentString()
Section titled “getIndentString()”getIndentString():
string
Defined in: WriterSync.ts:397
Returns
Section titled “Returns”string
Inherited from
Section titled “Inherited from”AbstractWriterSync.getIndentString
_closeStartElementTag()
Section titled “_closeStartElementTag()”
protected_closeStartElementTag():void
Defined in: WriterSync.ts:419
Returns
Section titled “Returns”void
Inherited from
Section titled “Inherited from”AbstractWriterSync._closeStartElementTag
_writeNewline()
Section titled “_writeNewline()”
protected_writeNewline():void
Defined in: WriterSync.ts:437
Returns
Section titled “Returns”void
Inherited from
Section titled “Inherited from”AbstractWriterSync._writeNewline
_emit()
Section titled “_emit()”
protected_emit(chunk):void
Defined in: WriterSync.ts:536
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”void
Overrides
Section titled “Overrides”AbstractWriterSync._emit
writeEndDocument()
Section titled “writeEndDocument()”writeEndDocument():
void
Defined in: WriterSync.ts:577
Indicates the end of the document and automatically closes all open elements.
Returns
Section titled “Returns”void
Overrides
Section titled “Overrides”AbstractWriterSync.writeEndDocument
flush()
Section titled “flush()”flush():
void
Defined in: WriterSync.ts:585
Returns
Section titled “Returns”void
close()
Section titled “close()”close():
void
Defined in: WriterSync.ts:592
Returns
Section titled “Returns”void
XmlArraySchema
Section titled “XmlArraySchema”Defined in: converter/XmlArraySchema.ts:16
Schema for parsing XML array values
Extends
Section titled “Extends”XmlSchemaBase<T["_output"][],T["_input"][]>
Type Parameters
Section titled “Type Parameters”T extends XmlSchemaBase<unknown, unknown>
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new XmlArraySchema<
T>(element,xpath?):XmlArraySchema<T>
Defined in: converter/XmlArraySchema.ts:19
Parameters
Section titled “Parameters”element
Section titled “element”T
xpath?
Section titled “xpath?”string
Returns
Section titled “Returns”Overrides
Section titled “Overrides”Properties
Section titled “Properties”element
Section titled “element”
readonlyelement:T
Defined in: converter/XmlArraySchema.ts:20
xpath?
Section titled “xpath?”
readonlyoptionalxpath?:string
Defined in: converter/XmlArraySchema.ts:21
_output
Section titled “_output”
readonly_output:T["_output"][]
Defined in: converter/base.ts:31
Inherited from
Section titled “Inherited from”_input
Section titled “_input”
readonly_input:T["_input"][]
Defined in: converter/base.ts:32
Inherited from
Section titled “Inherited from”Methods
Section titled “Methods”_parse()
Section titled “_parse()”_parse(
input,parseOptions?):T["_output"][]
Defined in: converter/XmlArraySchema.ts:26
Parse XML input synchronously
Parameters
Section titled “Parameters”XML string, byte view, or sync iterator
parseOptions?
Section titled “parseOptions?”Returns
Section titled “Returns”T["_output"][]
Parsed output
Throws
Section titled “Throws”If parsing fails
Overrides
Section titled “Overrides”_parseAsync()
Section titled “_parseAsync()”_parseAsync(
input,parseOptions?):Promise<T["_output"][]>
Defined in: converter/XmlArraySchema.ts:31
Parse XML input asynchronously
Parameters
Section titled “Parameters”XML string, stream, or async iterator
parseOptions?
Section titled “parseOptions?”Returns
Section titled “Returns”Promise<T["_output"][]>
Parsed output
Throws
Section titled “Throws”If parsing fails
Overrides
Section titled “Overrides”parse()
Section titled “parse()”parse(
input,options?):Promise<T["_output"][]>
Defined in: converter/base.ts:117
Parse XML asynchronously (public API)
Parameters
Section titled “Parameters”XML string, stream, or async iterator
options?
Section titled “options?”Parse options
Returns
Section titled “Returns”Promise<T["_output"][]>
Parsed output
Throws
Section titled “Throws”If parsing fails
Inherited from
Section titled “Inherited from”parseSync()
Section titled “parseSync()”parseSync(
input,options?):T["_output"][]
Defined in: converter/base.ts:135
Parse XML synchronously (public API)
Parameters
Section titled “Parameters”string | ArrayBufferView<ArrayBufferLike> | Iterator<AnyXmlEvent, any, any>
XML string or sync iterator
options?
Section titled “options?”Parse options
Returns
Section titled “Returns”T["_output"][]
Parsed output
Throws
Section titled “Throws”If parsing fails
Inherited from
Section titled “Inherited from”safeParse()
Section titled “safeParse()”safeParse(
input,options?):Promise<ParseResult<T["_output"][]>>
Defined in: converter/base.ts:152
Parse XML asynchronously with error handling
Parameters
Section titled “Parameters”XML string, stream, or async iterator
options?
Section titled “options?”Parse options
Returns
Section titled “Returns”Promise<ParseResult<T["_output"][]>>
Parse result with success flag
Inherited from
Section titled “Inherited from”safeParseSync()
Section titled “safeParseSync()”safeParseSync(
input,options?):ParseResult<T["_output"][]>
Defined in: converter/base.ts:173
Parse XML synchronously with error handling
Parameters
Section titled “Parameters”string | ArrayBufferView<ArrayBufferLike> | Iterator<AnyXmlEvent, any, any>
XML string, byte view, or sync iterator
options?
Section titled “options?”Parse options
Returns
Section titled “Returns”ParseResult<T["_output"][]>
Parse result with success flag
Inherited from
Section titled “Inherited from”transform()
Section titled “transform()”transform<
NewOutput>(fn):XmlSchemaBase<NewOutput,T["_input"][]>
Defined in: converter/base.ts:193
Transform the parsed output
Type Parameters
Section titled “Type Parameters”NewOutput
Section titled “NewOutput”NewOutput
Parameters
Section titled “Parameters”(value) => NewOutput
Transform function
Returns
Section titled “Returns”XmlSchemaBase<NewOutput, T["_input"][]>
New schema with transform applied
Inherited from
Section titled “Inherited from”optional()
Section titled “optional()”optional():
XmlSchemaBase<T["_output"][] |undefined,T["_input"][] |undefined>
Defined in: converter/base.ts:201
Make this schema optional
Returns
Section titled “Returns”XmlSchemaBase<T["_output"][] | undefined, T["_input"][] | undefined>
New optional schema
Inherited from
Section titled “Inherited from”array()
Section titled “array()”array(
xpath?):XmlSchemaBase<T["_output"][][],T["_input"][][]>
Defined in: converter/base.ts:210
Convert this schema to an array schema
Parameters
Section titled “Parameters”xpath?
Section titled “xpath?”string
XPath expression for array elements
Returns
Section titled “Returns”XmlSchemaBase<T["_output"][][], T["_input"][][]>
New array schema
Inherited from
Section titled “Inherited from”compile()
Section titled “compile()”compile():
XmlSchemaBase<T["_output"][],T["_input"][]>
Defined in: converter/base.ts:238
Compile this schema for repeated parsing.
Returns
Section titled “Returns”XmlSchemaBase<T["_output"][], T["_input"][]>
New compiled schema
Remarks
Section titled “Remarks”compile() preserves the public parsing API and can speed up schemas that can
be lowered to fixed XML event dispatch. The optimized path works best when the
root schema is an object, array, string, or number with static XPath selectors.
Fast-path friendly selectors use absolute paths such as /catalog/book,
descendant paths such as //book, and relative selectors inside object or
array items such as ./title, ./@id, ./name/text(), or ./name/@code.
Object fields, arrays of scalar values, arrays of objects, nested objects,
optional fields, and transforms are supported.
Selectors with wildcards or predicates, ambiguous relative paths such as
title, nested arrays, and arrays that combine an array XPath with an element
XPath are parsed with the normal runtime converter path instead. This keeps
behavior compatible, but does not get the dispatch fast path.
Call compile() once on the root schema and reuse the returned schema.
Non-object root schemas need an XPath.
Inherited from
Section titled “Inherited from”write()
Section titled “write()”write(
data,options?):Promise<string>
Defined in: converter/base.ts:249
Write data to XML string asynchronously (public API)
Parameters
Section titled “Parameters”T["_output"][]
Data to write
options?
Section titled “options?”Write options
Returns
Section titled “Returns”Promise<string>
XML string
Inherited from
Section titled “Inherited from”writeToStream()
Section titled “writeToStream()”writeToStream(
data,stream,options?):Promise<void>
Defined in: converter/base.ts:272
Write data to WritableStream asynchronously (public API)
Parameters
Section titled “Parameters”T["_output"][]
Data to write
stream
Section titled “stream”WritableStream<Uint8Array<ArrayBufferLike>>
Writable stream to write to
options?
Section titled “options?”Write options
Returns
Section titled “Returns”Promise<void>
Inherited from
Section titled “Inherited from”writeSync()
Section titled “writeSync()”writeSync(
data,options?):string
Defined in: converter/base.ts:286
Write data to XML string synchronously (public API)
Parameters
Section titled “Parameters”T["_output"][]
Data to write
options?
Section titled “options?”Write options
Returns
Section titled “Returns”string
XML string
Inherited from
Section titled “Inherited from”writer()
Section titled “writer()”writer(
config):this
Defined in: converter/base.ts:295
Configure writer settings for this schema
Parameters
Section titled “Parameters”config
Section titled “config”Writer configuration
Returns
Section titled “Returns”this
This schema with writer config
Inherited from
Section titled “Inherited from”XmlBuilder
Section titled “XmlBuilder”Defined in: converter/XmlBuilder.ts:13
Builder API for creating XML schemas
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new XmlBuilder():
XmlBuilder
Returns
Section titled “Returns”Methods
Section titled “Methods”string()
Section titled “string()”string(
xpath?):XmlStringSchema
Defined in: converter/XmlBuilder.ts:19
Create a string schema
Parameters
Section titled “Parameters”xpath?
Section titled “xpath?”string
Optional XPath expression
Returns
Section titled “Returns”String schema
number()
Section titled “number()”number(
xpath?):XmlNumberSchema
Defined in: converter/XmlBuilder.ts:28
Create a number schema
Parameters
Section titled “Parameters”xpath?
Section titled “xpath?”string
Optional XPath expression
Returns
Section titled “Returns”Number schema
object()
Section titled “object()”object<
T>(shape,options?):XmlObjectSchema<T>
Defined in: converter/XmlBuilder.ts:38
Create an object schema
Type Parameters
Section titled “Type Parameters”T extends XmlObjectShape
Parameters
Section titled “Parameters”T
Object shape definition
options?
Section titled “options?”Optional object options
Returns
Section titled “Returns”Object schema
array()
Section titled “array()”array<
T>(element,xpath?):XmlArraySchema<T>
Defined in: converter/XmlBuilder.ts:48
Create an array schema
Type Parameters
Section titled “Type Parameters”T extends XmlSchema<unknown, unknown>
Parameters
Section titled “Parameters”element
Section titled “element”T
Element schema
xpath?
Section titled “xpath?”string
XPath expression for array elements
Returns
Section titled “Returns”Array schema
XmlNumberSchema
Section titled “XmlNumberSchema”Defined in: converter/XmlNumberSchema.ts:16
Schema for parsing XML number values
Extends
Section titled “Extends”XmlSchema<number,number>
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new XmlNumberSchema(
options?):XmlNumberSchema
Defined in: converter/XmlNumberSchema.ts:19
Parameters
Section titled “Parameters”options?
Section titled “options?”XmlNumberOptions = {}
Returns
Section titled “Returns”Overrides
Section titled “Overrides”Properties
Section titled “Properties”options
Section titled “options”options:
XmlNumberOptions={}
Defined in: converter/XmlNumberSchema.ts:19
_output
Section titled “_output”
readonly_output:number
Defined in: converter/base.ts:31
Inherited from
Section titled “Inherited from”_input
Section titled “_input”
readonly_input:number
Defined in: converter/base.ts:32
Inherited from
Section titled “Inherited from”Methods
Section titled “Methods”_parse()
Section titled “_parse()”_parse(
input,parseOptions?):number
Defined in: converter/XmlNumberSchema.ts:23
Parse XML input synchronously
Parameters
Section titled “Parameters”XML string, byte view, or sync iterator
parseOptions?
Section titled “parseOptions?”Returns
Section titled “Returns”number
Parsed output
Throws
Section titled “Throws”If parsing fails
Overrides
Section titled “Overrides”_parseAsync()
Section titled “_parseAsync()”_parseAsync(
input,parseOptions?):Promise<number>
Defined in: converter/XmlNumberSchema.ts:29
Parse XML input asynchronously
Parameters
Section titled “Parameters”XML string, stream, or async iterator
parseOptions?
Section titled “parseOptions?”Returns
Section titled “Returns”Promise<number>
Parsed output
Throws
Section titled “Throws”If parsing fails
Overrides
Section titled “Overrides”xpath()
Section titled “xpath()”xpath(
path):XmlNumberSchema
Defined in: converter/XmlNumberSchema.ts:158
Set XPath expression for locating the element
Parameters
Section titled “Parameters”string
XPath expression
Returns
Section titled “Returns”New schema with XPath
min(
value):XmlNumberSchema
Defined in: converter/XmlNumberSchema.ts:171
Set minimum value
Parameters
Section titled “Parameters”number
Minimum value
Returns
Section titled “Returns”New schema with minimum
max(
value):XmlNumberSchema
Defined in: converter/XmlNumberSchema.ts:180
Set maximum value
Parameters
Section titled “Parameters”number
Maximum value
Returns
Section titled “Returns”New schema with maximum
int():
XmlNumberSchema
Defined in: converter/XmlNumberSchema.ts:188
Require integer value
Returns
Section titled “Returns”New schema that only accepts integers
parse()
Section titled “parse()”parse(
input,options?):Promise<number>
Defined in: converter/base.ts:117
Parse XML asynchronously (public API)
Parameters
Section titled “Parameters”XML string, stream, or async iterator
options?
Section titled “options?”Parse options
Returns
Section titled “Returns”Promise<number>
Parsed output
Throws
Section titled “Throws”If parsing fails
Inherited from
Section titled “Inherited from”parseSync()
Section titled “parseSync()”parseSync(
input,options?):number
Defined in: converter/base.ts:135
Parse XML synchronously (public API)
Parameters
Section titled “Parameters”string | ArrayBufferView<ArrayBufferLike> | Iterator<AnyXmlEvent, any, any>
XML string or sync iterator
options?
Section titled “options?”Parse options
Returns
Section titled “Returns”number
Parsed output
Throws
Section titled “Throws”If parsing fails
Inherited from
Section titled “Inherited from”safeParse()
Section titled “safeParse()”safeParse(
input,options?):Promise<ParseResult<number>>
Defined in: converter/base.ts:152
Parse XML asynchronously with error handling
Parameters
Section titled “Parameters”XML string, stream, or async iterator
options?
Section titled “options?”Parse options
Returns
Section titled “Returns”Promise<ParseResult<number>>
Parse result with success flag
Inherited from
Section titled “Inherited from”safeParseSync()
Section titled “safeParseSync()”safeParseSync(
input,options?):ParseResult<number>
Defined in: converter/base.ts:173
Parse XML synchronously with error handling
Parameters
Section titled “Parameters”string | ArrayBufferView<ArrayBufferLike> | Iterator<AnyXmlEvent, any, any>
XML string, byte view, or sync iterator
options?
Section titled “options?”Parse options
Returns
Section titled “Returns”ParseResult<number>
Parse result with success flag
Inherited from
Section titled “Inherited from”transform()
Section titled “transform()”transform<
NewOutput>(fn):XmlSchemaBase<NewOutput,number>
Defined in: converter/base.ts:193
Transform the parsed output
Type Parameters
Section titled “Type Parameters”NewOutput
Section titled “NewOutput”NewOutput
Parameters
Section titled “Parameters”(value) => NewOutput
Transform function
Returns
Section titled “Returns”XmlSchemaBase<NewOutput, number>
New schema with transform applied
Inherited from
Section titled “Inherited from”optional()
Section titled “optional()”optional():
XmlSchemaBase<number|undefined,number|undefined>
Defined in: converter/base.ts:201
Make this schema optional
Returns
Section titled “Returns”XmlSchemaBase<number | undefined, number | undefined>
New optional schema
Inherited from
Section titled “Inherited from”array()
Section titled “array()”array(
xpath?):XmlSchemaBase<number[],number[]>
Defined in: converter/base.ts:210
Convert this schema to an array schema
Parameters
Section titled “Parameters”xpath?
Section titled “xpath?”string
XPath expression for array elements
Returns
Section titled “Returns”XmlSchemaBase<number[], number[]>
New array schema
Inherited from
Section titled “Inherited from”compile()
Section titled “compile()”compile():
XmlSchemaBase<number,number>
Defined in: converter/base.ts:238
Compile this schema for repeated parsing.
Returns
Section titled “Returns”XmlSchemaBase<number, number>
New compiled schema
Remarks
Section titled “Remarks”compile() preserves the public parsing API and can speed up schemas that can
be lowered to fixed XML event dispatch. The optimized path works best when the
root schema is an object, array, string, or number with static XPath selectors.
Fast-path friendly selectors use absolute paths such as /catalog/book,
descendant paths such as //book, and relative selectors inside object or
array items such as ./title, ./@id, ./name/text(), or ./name/@code.
Object fields, arrays of scalar values, arrays of objects, nested objects,
optional fields, and transforms are supported.
Selectors with wildcards or predicates, ambiguous relative paths such as
title, nested arrays, and arrays that combine an array XPath with an element
XPath are parsed with the normal runtime converter path instead. This keeps
behavior compatible, but does not get the dispatch fast path.
Call compile() once on the root schema and reuse the returned schema.
Non-object root schemas need an XPath.
Inherited from
Section titled “Inherited from”write()
Section titled “write()”write(
data,options?):Promise<string>
Defined in: converter/base.ts:249
Write data to XML string asynchronously (public API)
Parameters
Section titled “Parameters”number
Data to write
options?
Section titled “options?”Write options
Returns
Section titled “Returns”Promise<string>
XML string
Inherited from
Section titled “Inherited from”writeToStream()
Section titled “writeToStream()”writeToStream(
data,stream,options?):Promise<void>
Defined in: converter/base.ts:272
Write data to WritableStream asynchronously (public API)
Parameters
Section titled “Parameters”number
Data to write
stream
Section titled “stream”WritableStream<Uint8Array<ArrayBufferLike>>
Writable stream to write to
options?
Section titled “options?”Write options
Returns
Section titled “Returns”Promise<void>
Inherited from
Section titled “Inherited from”writeSync()
Section titled “writeSync()”writeSync(
data,options?):string
Defined in: converter/base.ts:286
Write data to XML string synchronously (public API)
Parameters
Section titled “Parameters”number
Data to write
options?
Section titled “options?”Write options
Returns
Section titled “Returns”string
XML string
Inherited from
Section titled “Inherited from”writer()
Section titled “writer()”writer(
config):this
Defined in: converter/base.ts:295
Configure writer settings for this schema
Parameters
Section titled “Parameters”config
Section titled “config”Writer configuration
Returns
Section titled “Returns”this
This schema with writer config
Inherited from
Section titled “Inherited from”XmlObjectSchema
Section titled “XmlObjectSchema”Defined in: converter/XmlObjectSchema.ts:58
Schema for parsing XML object values
Extends
Section titled “Extends”XmlSchema<InferObjectOutput<T>,unknown>
Type Parameters
Section titled “Type Parameters”T extends XmlObjectShape
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new XmlObjectSchema<
T>(shape,options?):XmlObjectSchema<T>
Defined in: converter/XmlObjectSchema.ts:61
Parameters
Section titled “Parameters”T
options?
Section titled “options?”XmlObjectOptions = {}
Returns
Section titled “Returns”Overrides
Section titled “Overrides”Properties
Section titled “Properties”
readonlyshape:T
Defined in: converter/XmlObjectSchema.ts:62
options
Section titled “options”options:
XmlObjectOptions={}
Defined in: converter/XmlObjectSchema.ts:63
_output
Section titled “_output”
readonly_output:Output
Defined in: converter/base.ts:31
Inherited from
Section titled “Inherited from”_input
Section titled “_input”
readonly_input:unknown
Defined in: converter/base.ts:32
Inherited from
Section titled “Inherited from”Methods
Section titled “Methods”_parse()
Section titled “_parse()”_parse(
input,parseOptions?):InferObjectOutput<T>
Defined in: converter/XmlObjectSchema.ts:68
Parse XML input synchronously
Parameters
Section titled “Parameters”XML string, byte view, or sync iterator
parseOptions?
Section titled “parseOptions?”Returns
Section titled “Returns”Parsed output
Throws
Section titled “Throws”If parsing fails
Overrides
Section titled “Overrides”_parseAsync()
Section titled “_parseAsync()”_parseAsync(
input,parseOptions?):Promise<InferObjectOutput<T>>
Defined in: converter/XmlObjectSchema.ts:73
Parse XML input asynchronously
Parameters
Section titled “Parameters”XML string, stream, or async iterator
parseOptions?
Section titled “parseOptions?”Returns
Section titled “Returns”Promise<InferObjectOutput<T>>
Parsed output
Throws
Section titled “Throws”If parsing fails
Overrides
Section titled “Overrides”xpath()
Section titled “xpath()”xpath(
path):XmlObjectSchema<T>
Defined in: converter/XmlObjectSchema.ts:126
Set XPath expression for locating the object
Parameters
Section titled “Parameters”string
XPath expression
Returns
Section titled “Returns”New schema with XPath
parse()
Section titled “parse()”parse(
input,options?):Promise<InferObjectOutput<T>>
Defined in: converter/base.ts:117
Parse XML asynchronously (public API)
Parameters
Section titled “Parameters”XML string, stream, or async iterator
options?
Section titled “options?”Parse options
Returns
Section titled “Returns”Promise<InferObjectOutput<T>>
Parsed output
Throws
Section titled “Throws”If parsing fails
Inherited from
Section titled “Inherited from”parseSync()
Section titled “parseSync()”parseSync(
input,options?):Output
Defined in: converter/base.ts:135
Parse XML synchronously (public API)
Parameters
Section titled “Parameters”string | ArrayBufferView<ArrayBufferLike> | Iterator<AnyXmlEvent, any, any>
XML string or sync iterator
options?
Section titled “options?”Parse options
Returns
Section titled “Returns”Output
Parsed output
Throws
Section titled “Throws”If parsing fails
Inherited from
Section titled “Inherited from”safeParse()
Section titled “safeParse()”safeParse(
input,options?):Promise<ParseResult<InferObjectOutput<T>>>
Defined in: converter/base.ts:152
Parse XML asynchronously with error handling
Parameters
Section titled “Parameters”XML string, stream, or async iterator
options?
Section titled “options?”Parse options
Returns
Section titled “Returns”Promise<ParseResult<InferObjectOutput<T>>>
Parse result with success flag
Inherited from
Section titled “Inherited from”safeParseSync()
Section titled “safeParseSync()”safeParseSync(
input,options?):ParseResult<InferObjectOutput<T>>
Defined in: converter/base.ts:173
Parse XML synchronously with error handling
Parameters
Section titled “Parameters”string | ArrayBufferView<ArrayBufferLike> | Iterator<AnyXmlEvent, any, any>
XML string, byte view, or sync iterator
options?
Section titled “options?”Parse options
Returns
Section titled “Returns”ParseResult<InferObjectOutput<T>>
Parse result with success flag
Inherited from
Section titled “Inherited from”transform()
Section titled “transform()”transform<
NewOutput>(fn):XmlSchemaBase<NewOutput,unknown>
Defined in: converter/base.ts:193
Transform the parsed output
Type Parameters
Section titled “Type Parameters”NewOutput
Section titled “NewOutput”NewOutput
Parameters
Section titled “Parameters”(value) => NewOutput
Transform function
Returns
Section titled “Returns”XmlSchemaBase<NewOutput, unknown>
New schema with transform applied
Inherited from
Section titled “Inherited from”optional()
Section titled “optional()”optional():
XmlSchemaBase<InferObjectOutput<T> |undefined,unknown>
Defined in: converter/base.ts:201
Make this schema optional
Returns
Section titled “Returns”XmlSchemaBase<InferObjectOutput<T> | undefined, unknown>
New optional schema
Inherited from
Section titled “Inherited from”array()
Section titled “array()”array(
xpath?):XmlSchemaBase<InferObjectOutput<T>[],unknown[]>
Defined in: converter/base.ts:210
Convert this schema to an array schema
Parameters
Section titled “Parameters”xpath?
Section titled “xpath?”string
XPath expression for array elements
Returns
Section titled “Returns”XmlSchemaBase<InferObjectOutput<T>[], unknown[]>
New array schema
Inherited from
Section titled “Inherited from”compile()
Section titled “compile()”compile():
XmlSchemaBase<InferObjectOutput<T>,unknown>
Defined in: converter/base.ts:238
Compile this schema for repeated parsing.
Returns
Section titled “Returns”XmlSchemaBase<InferObjectOutput<T>, unknown>
New compiled schema
Remarks
Section titled “Remarks”compile() preserves the public parsing API and can speed up schemas that can
be lowered to fixed XML event dispatch. The optimized path works best when the
root schema is an object, array, string, or number with static XPath selectors.
Fast-path friendly selectors use absolute paths such as /catalog/book,
descendant paths such as //book, and relative selectors inside object or
array items such as ./title, ./@id, ./name/text(), or ./name/@code.
Object fields, arrays of scalar values, arrays of objects, nested objects,
optional fields, and transforms are supported.
Selectors with wildcards or predicates, ambiguous relative paths such as
title, nested arrays, and arrays that combine an array XPath with an element
XPath are parsed with the normal runtime converter path instead. This keeps
behavior compatible, but does not get the dispatch fast path.
Call compile() once on the root schema and reuse the returned schema.
Non-object root schemas need an XPath.
Inherited from
Section titled “Inherited from”write()
Section titled “write()”write(
data,options?):Promise<string>
Defined in: converter/base.ts:249
Write data to XML string asynchronously (public API)
Parameters
Section titled “Parameters”Output
Data to write
options?
Section titled “options?”Write options
Returns
Section titled “Returns”Promise<string>
XML string
Inherited from
Section titled “Inherited from”writeToStream()
Section titled “writeToStream()”writeToStream(
data,stream,options?):Promise<void>
Defined in: converter/base.ts:272
Write data to WritableStream asynchronously (public API)
Parameters
Section titled “Parameters”Output
Data to write
stream
Section titled “stream”WritableStream<Uint8Array<ArrayBufferLike>>
Writable stream to write to
options?
Section titled “options?”Write options
Returns
Section titled “Returns”Promise<void>
Inherited from
Section titled “Inherited from”writeSync()
Section titled “writeSync()”writeSync(
data,options?):string
Defined in: converter/base.ts:286
Write data to XML string synchronously (public API)
Parameters
Section titled “Parameters”Output
Data to write
options?
Section titled “options?”Write options
Returns
Section titled “Returns”string
XML string
Inherited from
Section titled “Inherited from”writer()
Section titled “writer()”writer(
config):this
Defined in: converter/base.ts:295
Configure writer settings for this schema
Parameters
Section titled “Parameters”config
Section titled “config”Writer configuration
Returns
Section titled “Returns”this
This schema with writer config
Inherited from
Section titled “Inherited from”XmlOptionalSchema
Section titled “XmlOptionalSchema”Defined in: converter/XmlOptionalSchema.ts:10
Schema for optional values
Extends
Section titled “Extends”XmlSchemaBase<T["_output"] |undefined,T["_input"] |undefined>
Type Parameters
Section titled “Type Parameters”T extends XmlSchemaBase<unknown, unknown>
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new XmlOptionalSchema<
T>(schema):XmlOptionalSchema<T>
Defined in: converter/XmlOptionalSchema.ts:13
Parameters
Section titled “Parameters”schema
Section titled “schema”T
Returns
Section titled “Returns”Overrides
Section titled “Overrides”Properties
Section titled “Properties”schema
Section titled “schema”
readonlyschema:T
Defined in: converter/XmlOptionalSchema.ts:13
_output
Section titled “_output”
readonly_output:T["_output"] |undefined
Defined in: converter/base.ts:31
Inherited from
Section titled “Inherited from”_input
Section titled “_input”
readonly_input:T["_input"] |undefined
Defined in: converter/base.ts:32
Inherited from
Section titled “Inherited from”Methods
Section titled “Methods”_parse()
Section titled “_parse()”_parse(
input,options?):T["_output"] |undefined
Defined in: converter/XmlOptionalSchema.ts:17
Parse XML input synchronously
Parameters
Section titled “Parameters”XML string, byte view, or sync iterator
options?
Section titled “options?”Parse options
Returns
Section titled “Returns”T["_output"] | undefined
Parsed output
Throws
Section titled “Throws”If parsing fails
Overrides
Section titled “Overrides”_parseAsync()
Section titled “_parseAsync()”_parseAsync(
input,options?):Promise<T["_output"] |undefined>
Defined in: converter/XmlOptionalSchema.ts:30
Parse XML input asynchronously
Parameters
Section titled “Parameters”XML string, stream, or async iterator
options?
Section titled “options?”Parse options
Returns
Section titled “Returns”Promise<T["_output"] | undefined>
Parsed output
Throws
Section titled “Throws”If parsing fails
Overrides
Section titled “Overrides”parse()
Section titled “parse()”parse(
input,options?):Promise<T["_output"] |undefined>
Defined in: converter/base.ts:117
Parse XML asynchronously (public API)
Parameters
Section titled “Parameters”XML string, stream, or async iterator
options?
Section titled “options?”Parse options
Returns
Section titled “Returns”Promise<T["_output"] | undefined>
Parsed output
Throws
Section titled “Throws”If parsing fails
Inherited from
Section titled “Inherited from”parseSync()
Section titled “parseSync()”parseSync(
input,options?):T["_output"] |undefined
Defined in: converter/base.ts:135
Parse XML synchronously (public API)
Parameters
Section titled “Parameters”string | ArrayBufferView<ArrayBufferLike> | Iterator<AnyXmlEvent, any, any>
XML string or sync iterator
options?
Section titled “options?”Parse options
Returns
Section titled “Returns”T["_output"] | undefined
Parsed output
Throws
Section titled “Throws”If parsing fails
Inherited from
Section titled “Inherited from”safeParse()
Section titled “safeParse()”safeParse(
input,options?):Promise<ParseResult<T["_output"] |undefined>>
Defined in: converter/base.ts:152
Parse XML asynchronously with error handling
Parameters
Section titled “Parameters”XML string, stream, or async iterator
options?
Section titled “options?”Parse options
Returns
Section titled “Returns”Promise<ParseResult<T["_output"] | undefined>>
Parse result with success flag
Inherited from
Section titled “Inherited from”safeParseSync()
Section titled “safeParseSync()”safeParseSync(
input,options?):ParseResult<T["_output"] |undefined>
Defined in: converter/base.ts:173
Parse XML synchronously with error handling
Parameters
Section titled “Parameters”string | ArrayBufferView<ArrayBufferLike> | Iterator<AnyXmlEvent, any, any>
XML string, byte view, or sync iterator
options?
Section titled “options?”Parse options
Returns
Section titled “Returns”ParseResult<T["_output"] | undefined>
Parse result with success flag
Inherited from
Section titled “Inherited from”transform()
Section titled “transform()”transform<
NewOutput>(fn):XmlSchemaBase<NewOutput,T["_input"] |undefined>
Defined in: converter/base.ts:193
Transform the parsed output
Type Parameters
Section titled “Type Parameters”NewOutput
Section titled “NewOutput”NewOutput
Parameters
Section titled “Parameters”(value) => NewOutput
Transform function
Returns
Section titled “Returns”XmlSchemaBase<NewOutput, T["_input"] | undefined>
New schema with transform applied
Inherited from
Section titled “Inherited from”optional()
Section titled “optional()”optional():
XmlSchemaBase<T["_output"] |undefined,T["_input"] |undefined>
Defined in: converter/base.ts:201
Make this schema optional
Returns
Section titled “Returns”XmlSchemaBase<T["_output"] | undefined, T["_input"] | undefined>
New optional schema
Inherited from
Section titled “Inherited from”array()
Section titled “array()”array(
xpath?):XmlSchemaBase<(T["_output"] |undefined)[], (T["_input"] |undefined)[]>
Defined in: converter/base.ts:210
Convert this schema to an array schema
Parameters
Section titled “Parameters”xpath?
Section titled “xpath?”string
XPath expression for array elements
Returns
Section titled “Returns”XmlSchemaBase<(T["_output"] | undefined)[], (T["_input"] | undefined)[]>
New array schema
Inherited from
Section titled “Inherited from”compile()
Section titled “compile()”compile():
XmlSchemaBase<T["_output"] |undefined,T["_input"] |undefined>
Defined in: converter/base.ts:238
Compile this schema for repeated parsing.
Returns
Section titled “Returns”XmlSchemaBase<T["_output"] | undefined, T["_input"] | undefined>
New compiled schema
Remarks
Section titled “Remarks”compile() preserves the public parsing API and can speed up schemas that can
be lowered to fixed XML event dispatch. The optimized path works best when the
root schema is an object, array, string, or number with static XPath selectors.
Fast-path friendly selectors use absolute paths such as /catalog/book,
descendant paths such as //book, and relative selectors inside object or
array items such as ./title, ./@id, ./name/text(), or ./name/@code.
Object fields, arrays of scalar values, arrays of objects, nested objects,
optional fields, and transforms are supported.
Selectors with wildcards or predicates, ambiguous relative paths such as
title, nested arrays, and arrays that combine an array XPath with an element
XPath are parsed with the normal runtime converter path instead. This keeps
behavior compatible, but does not get the dispatch fast path.
Call compile() once on the root schema and reuse the returned schema.
Non-object root schemas need an XPath.
Inherited from
Section titled “Inherited from”write()
Section titled “write()”write(
data,options?):Promise<string>
Defined in: converter/base.ts:249
Write data to XML string asynchronously (public API)
Parameters
Section titled “Parameters”T["_output"] | undefined
Data to write
options?
Section titled “options?”Write options
Returns
Section titled “Returns”Promise<string>
XML string
Inherited from
Section titled “Inherited from”writeToStream()
Section titled “writeToStream()”writeToStream(
data,stream,options?):Promise<void>
Defined in: converter/base.ts:272
Write data to WritableStream asynchronously (public API)
Parameters
Section titled “Parameters”T["_output"] | undefined
Data to write
stream
Section titled “stream”WritableStream<Uint8Array<ArrayBufferLike>>
Writable stream to write to
options?
Section titled “options?”Write options
Returns
Section titled “Returns”Promise<void>
Inherited from
Section titled “Inherited from”writeSync()
Section titled “writeSync()”writeSync(
data,options?):string
Defined in: converter/base.ts:286
Write data to XML string synchronously (public API)
Parameters
Section titled “Parameters”T["_output"] | undefined
Data to write
options?
Section titled “options?”Write options
Returns
Section titled “Returns”string
XML string
Inherited from
Section titled “Inherited from”writer()
Section titled “writer()”writer(
config):this
Defined in: converter/base.ts:295
Configure writer settings for this schema
Parameters
Section titled “Parameters”config
Section titled “config”Writer configuration
Returns
Section titled “Returns”this
This schema with writer config
Inherited from
Section titled “Inherited from”abstract XmlSchema
Section titled “abstract XmlSchema”Defined in: converter/XmlSchema.ts:10
Main XML schema class (extends XmlSchemaBase with all methods)
Extends
Section titled “Extends”XmlSchemaBase<Output,Input>
Extended by
Section titled “Extended by”Type Parameters
Section titled “Type Parameters”Output
Section titled “Output”Output
Input = Output
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new XmlSchema<
Output,Input>():XmlSchema<Output,Input>
Returns
Section titled “Returns”XmlSchema<Output, Input>
Inherited from
Section titled “Inherited from”Properties
Section titled “Properties”_output
Section titled “_output”
readonly_output:Output
Defined in: converter/base.ts:31
Inherited from
Section titled “Inherited from”_input
Section titled “_input”
readonly_input:Input
Defined in: converter/base.ts:32
Inherited from
Section titled “Inherited from”Methods
Section titled “Methods”_parse()
Section titled “_parse()”
abstract_parse(input,options?):Output
Defined in: converter/base.ts:53
Parse XML input synchronously
Parameters
Section titled “Parameters”XML string, byte view, or sync iterator
options?
Section titled “options?”Parse options
Returns
Section titled “Returns”Output
Parsed output
Throws
Section titled “Throws”If parsing fails
Inherited from
Section titled “Inherited from”_parseAsync()
Section titled “_parseAsync()”
abstract_parseAsync(input,options?):Promise<Output>
Defined in: converter/base.ts:62
Parse XML input asynchronously
Parameters
Section titled “Parameters”XML string, stream, or async iterator
options?
Section titled “options?”Parse options
Returns
Section titled “Returns”Promise<Output>
Parsed output
Throws
Section titled “Throws”If parsing fails
Inherited from
Section titled “Inherited from”parse()
Section titled “parse()”parse(
input,options?):Promise<Output>
Defined in: converter/base.ts:117
Parse XML asynchronously (public API)
Parameters
Section titled “Parameters”XML string, stream, or async iterator
options?
Section titled “options?”Parse options
Returns
Section titled “Returns”Promise<Output>
Parsed output
Throws
Section titled “Throws”If parsing fails
Inherited from
Section titled “Inherited from”parseSync()
Section titled “parseSync()”parseSync(
input,options?):Output
Defined in: converter/base.ts:135
Parse XML synchronously (public API)
Parameters
Section titled “Parameters”string | ArrayBufferView<ArrayBufferLike> | Iterator<AnyXmlEvent, any, any>
XML string or sync iterator
options?
Section titled “options?”Parse options
Returns
Section titled “Returns”Output
Parsed output
Throws
Section titled “Throws”If parsing fails
Inherited from
Section titled “Inherited from”safeParse()
Section titled “safeParse()”safeParse(
input,options?):Promise<ParseResult<Output>>
Defined in: converter/base.ts:152
Parse XML asynchronously with error handling
Parameters
Section titled “Parameters”XML string, stream, or async iterator
options?
Section titled “options?”Parse options
Returns
Section titled “Returns”Promise<ParseResult<Output>>
Parse result with success flag
Inherited from
Section titled “Inherited from”safeParseSync()
Section titled “safeParseSync()”safeParseSync(
input,options?):ParseResult<Output>
Defined in: converter/base.ts:173
Parse XML synchronously with error handling
Parameters
Section titled “Parameters”string | ArrayBufferView<ArrayBufferLike> | Iterator<AnyXmlEvent, any, any>
XML string, byte view, or sync iterator
options?
Section titled “options?”Parse options
Returns
Section titled “Returns”ParseResult<Output>
Parse result with success flag
Inherited from
Section titled “Inherited from”transform()
Section titled “transform()”transform<
NewOutput>(fn):XmlSchemaBase<NewOutput,Input>
Defined in: converter/base.ts:193
Transform the parsed output
Type Parameters
Section titled “Type Parameters”NewOutput
Section titled “NewOutput”NewOutput
Parameters
Section titled “Parameters”(value) => NewOutput
Transform function
Returns
Section titled “Returns”XmlSchemaBase<NewOutput, Input>
New schema with transform applied
Inherited from
Section titled “Inherited from”optional()
Section titled “optional()”optional():
XmlSchemaBase<Output|undefined,Input|undefined>
Defined in: converter/base.ts:201
Make this schema optional
Returns
Section titled “Returns”XmlSchemaBase<Output | undefined, Input | undefined>
New optional schema
Inherited from
Section titled “Inherited from”array()
Section titled “array()”array(
xpath?):XmlSchemaBase<Output[],Input[]>
Defined in: converter/base.ts:210
Convert this schema to an array schema
Parameters
Section titled “Parameters”xpath?
Section titled “xpath?”string
XPath expression for array elements
Returns
Section titled “Returns”XmlSchemaBase<Output[], Input[]>
New array schema
Inherited from
Section titled “Inherited from”compile()
Section titled “compile()”compile():
XmlSchemaBase<Output,Input>
Defined in: converter/base.ts:238
Compile this schema for repeated parsing.
Returns
Section titled “Returns”XmlSchemaBase<Output, Input>
New compiled schema
Remarks
Section titled “Remarks”compile() preserves the public parsing API and can speed up schemas that can
be lowered to fixed XML event dispatch. The optimized path works best when the
root schema is an object, array, string, or number with static XPath selectors.
Fast-path friendly selectors use absolute paths such as /catalog/book,
descendant paths such as //book, and relative selectors inside object or
array items such as ./title, ./@id, ./name/text(), or ./name/@code.
Object fields, arrays of scalar values, arrays of objects, nested objects,
optional fields, and transforms are supported.
Selectors with wildcards or predicates, ambiguous relative paths such as
title, nested arrays, and arrays that combine an array XPath with an element
XPath are parsed with the normal runtime converter path instead. This keeps
behavior compatible, but does not get the dispatch fast path.
Call compile() once on the root schema and reuse the returned schema.
Non-object root schemas need an XPath.
Inherited from
Section titled “Inherited from”write()
Section titled “write()”write(
data,options?):Promise<string>
Defined in: converter/base.ts:249
Write data to XML string asynchronously (public API)
Parameters
Section titled “Parameters”Output
Data to write
options?
Section titled “options?”Write options
Returns
Section titled “Returns”Promise<string>
XML string
Inherited from
Section titled “Inherited from”writeToStream()
Section titled “writeToStream()”writeToStream(
data,stream,options?):Promise<void>
Defined in: converter/base.ts:272
Write data to WritableStream asynchronously (public API)
Parameters
Section titled “Parameters”Output
Data to write
stream
Section titled “stream”WritableStream<Uint8Array<ArrayBufferLike>>
Writable stream to write to
options?
Section titled “options?”Write options
Returns
Section titled “Returns”Promise<void>
Inherited from
Section titled “Inherited from”writeSync()
Section titled “writeSync()”writeSync(
data,options?):string
Defined in: converter/base.ts:286
Write data to XML string synchronously (public API)
Parameters
Section titled “Parameters”Output
Data to write
options?
Section titled “options?”Write options
Returns
Section titled “Returns”string
XML string
Inherited from
Section titled “Inherited from”writer()
Section titled “writer()”writer(
config):this
Defined in: converter/base.ts:295
Configure writer settings for this schema
Parameters
Section titled “Parameters”config
Section titled “config”Writer configuration
Returns
Section titled “Returns”this
This schema with writer config
Inherited from
Section titled “Inherited from”XmlStringSchema
Section titled “XmlStringSchema”Defined in: converter/XmlStringSchema.ts:27
Schema for parsing XML string values
Extends
Section titled “Extends”XmlSchema<string,string>
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new XmlStringSchema(
options?):XmlStringSchema
Defined in: converter/XmlStringSchema.ts:30
Parameters
Section titled “Parameters”options?
Section titled “options?”XmlStringOptions = {}
Returns
Section titled “Returns”Overrides
Section titled “Overrides”Properties
Section titled “Properties”options
Section titled “options”options:
XmlStringOptions={}
Defined in: converter/XmlStringSchema.ts:30
_output
Section titled “_output”
readonly_output:string
Defined in: converter/base.ts:31
Inherited from
Section titled “Inherited from”_input
Section titled “_input”
readonly_input:string
Defined in: converter/base.ts:32
Inherited from
Section titled “Inherited from”Methods
Section titled “Methods”_parse()
Section titled “_parse()”_parse(
input,parseOptions?):string
Defined in: converter/XmlStringSchema.ts:34
Parse XML input synchronously
Parameters
Section titled “Parameters”XML string, byte view, or sync iterator
parseOptions?
Section titled “parseOptions?”Returns
Section titled “Returns”string
Parsed output
Throws
Section titled “Throws”If parsing fails
Overrides
Section titled “Overrides”_parseAsync()
Section titled “_parseAsync()”_parseAsync(
input,parseOptions?):Promise<string>
Defined in: converter/XmlStringSchema.ts:39
Parse XML input asynchronously
Parameters
Section titled “Parameters”XML string, stream, or async iterator
parseOptions?
Section titled “parseOptions?”Returns
Section titled “Returns”Promise<string>
Parsed output
Throws
Section titled “Throws”If parsing fails
Overrides
Section titled “Overrides”xpath()
Section titled “xpath()”xpath(
path):XmlStringSchema
Defined in: converter/XmlStringSchema.ts:123
Set XPath expression for locating the element
Parameters
Section titled “Parameters”string
XPath expression
Returns
Section titled “Returns”New schema with XPath
parse()
Section titled “parse()”parse(
input,options?):Promise<string>
Defined in: converter/base.ts:117
Parse XML asynchronously (public API)
Parameters
Section titled “Parameters”XML string, stream, or async iterator
options?
Section titled “options?”Parse options
Returns
Section titled “Returns”Promise<string>
Parsed output
Throws
Section titled “Throws”If parsing fails
Inherited from
Section titled “Inherited from”parseSync()
Section titled “parseSync()”parseSync(
input,options?):string
Defined in: converter/base.ts:135
Parse XML synchronously (public API)
Parameters
Section titled “Parameters”string | ArrayBufferView<ArrayBufferLike> | Iterator<AnyXmlEvent, any, any>
XML string or sync iterator
options?
Section titled “options?”Parse options
Returns
Section titled “Returns”string
Parsed output
Throws
Section titled “Throws”If parsing fails
Inherited from
Section titled “Inherited from”safeParse()
Section titled “safeParse()”safeParse(
input,options?):Promise<ParseResult<string>>
Defined in: converter/base.ts:152
Parse XML asynchronously with error handling
Parameters
Section titled “Parameters”XML string, stream, or async iterator
options?
Section titled “options?”Parse options
Returns
Section titled “Returns”Promise<ParseResult<string>>
Parse result with success flag
Inherited from
Section titled “Inherited from”safeParseSync()
Section titled “safeParseSync()”safeParseSync(
input,options?):ParseResult<string>
Defined in: converter/base.ts:173
Parse XML synchronously with error handling
Parameters
Section titled “Parameters”string | ArrayBufferView<ArrayBufferLike> | Iterator<AnyXmlEvent, any, any>
XML string, byte view, or sync iterator
options?
Section titled “options?”Parse options
Returns
Section titled “Returns”ParseResult<string>
Parse result with success flag
Inherited from
Section titled “Inherited from”transform()
Section titled “transform()”transform<
NewOutput>(fn):XmlSchemaBase<NewOutput,string>
Defined in: converter/base.ts:193
Transform the parsed output
Type Parameters
Section titled “Type Parameters”NewOutput
Section titled “NewOutput”NewOutput
Parameters
Section titled “Parameters”(value) => NewOutput
Transform function
Returns
Section titled “Returns”XmlSchemaBase<NewOutput, string>
New schema with transform applied
Inherited from
Section titled “Inherited from”optional()
Section titled “optional()”optional():
XmlSchemaBase<string|undefined,string|undefined>
Defined in: converter/base.ts:201
Make this schema optional
Returns
Section titled “Returns”XmlSchemaBase<string | undefined, string | undefined>
New optional schema
Inherited from
Section titled “Inherited from”array()
Section titled “array()”array(
xpath?):XmlSchemaBase<string[],string[]>
Defined in: converter/base.ts:210
Convert this schema to an array schema
Parameters
Section titled “Parameters”xpath?
Section titled “xpath?”string
XPath expression for array elements
Returns
Section titled “Returns”XmlSchemaBase<string[], string[]>
New array schema
Inherited from
Section titled “Inherited from”compile()
Section titled “compile()”compile():
XmlSchemaBase<string,string>
Defined in: converter/base.ts:238
Compile this schema for repeated parsing.
Returns
Section titled “Returns”XmlSchemaBase<string, string>
New compiled schema
Remarks
Section titled “Remarks”compile() preserves the public parsing API and can speed up schemas that can
be lowered to fixed XML event dispatch. The optimized path works best when the
root schema is an object, array, string, or number with static XPath selectors.
Fast-path friendly selectors use absolute paths such as /catalog/book,
descendant paths such as //book, and relative selectors inside object or
array items such as ./title, ./@id, ./name/text(), or ./name/@code.
Object fields, arrays of scalar values, arrays of objects, nested objects,
optional fields, and transforms are supported.
Selectors with wildcards or predicates, ambiguous relative paths such as
title, nested arrays, and arrays that combine an array XPath with an element
XPath are parsed with the normal runtime converter path instead. This keeps
behavior compatible, but does not get the dispatch fast path.
Call compile() once on the root schema and reuse the returned schema.
Non-object root schemas need an XPath.
Inherited from
Section titled “Inherited from”write()
Section titled “write()”write(
data,options?):Promise<string>
Defined in: converter/base.ts:249
Write data to XML string asynchronously (public API)
Parameters
Section titled “Parameters”string
Data to write
options?
Section titled “options?”Write options
Returns
Section titled “Returns”Promise<string>
XML string
Inherited from
Section titled “Inherited from”writeToStream()
Section titled “writeToStream()”writeToStream(
data,stream,options?):Promise<void>
Defined in: converter/base.ts:272
Write data to WritableStream asynchronously (public API)
Parameters
Section titled “Parameters”string
Data to write
stream
Section titled “stream”WritableStream<Uint8Array<ArrayBufferLike>>
Writable stream to write to
options?
Section titled “options?”Write options
Returns
Section titled “Returns”Promise<void>
Inherited from
Section titled “Inherited from”writeSync()
Section titled “writeSync()”writeSync(
data,options?):string
Defined in: converter/base.ts:286
Write data to XML string synchronously (public API)
Parameters
Section titled “Parameters”string
Data to write
options?
Section titled “options?”Write options
Returns
Section titled “Returns”string
XML string
Inherited from
Section titled “Inherited from”writer()
Section titled “writer()”writer(
config):this
Defined in: converter/base.ts:295
Configure writer settings for this schema
Parameters
Section titled “Parameters”config
Section titled “config”Writer configuration
Returns
Section titled “Returns”this
This schema with writer config
Inherited from
Section titled “Inherited from”XmlTransformSchema
Section titled “XmlTransformSchema”Defined in: converter/XmlTransformSchema.ts:11
Schema for transforming parsed values
Extends
Section titled “Extends”XmlSchemaBase<Output,Input>
Type Parameters
Section titled “Type Parameters”Output
Section titled “Output”Output
Input
IntermediateOutput
Section titled “IntermediateOutput”IntermediateOutput = unknown
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new XmlTransformSchema<
Output,Input,IntermediateOutput>(schema,transformFn):XmlTransformSchema<Output,Input,IntermediateOutput>
Defined in: converter/XmlTransformSchema.ts:19
Parameters
Section titled “Parameters”schema
Section titled “schema”XmlSchemaBase<IntermediateOutput, Input>
transformFn
Section titled “transformFn”(value) => Output
Returns
Section titled “Returns”XmlTransformSchema<Output, Input, IntermediateOutput>
Overrides
Section titled “Overrides”Properties
Section titled “Properties”_output
Section titled “_output”
readonly_output:Output
Defined in: converter/base.ts:31
Inherited from
Section titled “Inherited from”_input
Section titled “_input”
readonly_input:Input
Defined in: converter/base.ts:32
Inherited from
Section titled “Inherited from”Methods
Section titled “Methods”_parse()
Section titled “_parse()”_parse(
input,options?):Output
Defined in: converter/XmlTransformSchema.ts:28
Parse XML input synchronously
Parameters
Section titled “Parameters”XML string, byte view, or sync iterator
options?
Section titled “options?”Parse options
Returns
Section titled “Returns”Output
Parsed output
Throws
Section titled “Throws”If parsing fails
Overrides
Section titled “Overrides”_parseAsync()
Section titled “_parseAsync()”_parseAsync(
input,options?):Promise<Output>
Defined in: converter/XmlTransformSchema.ts:33
Parse XML input asynchronously
Parameters
Section titled “Parameters”XML string, stream, or async iterator
options?
Section titled “options?”Parse options
Returns
Section titled “Returns”Promise<Output>
Parsed output
Throws
Section titled “Throws”If parsing fails
Overrides
Section titled “Overrides”parse()
Section titled “parse()”parse(
input,options?):Promise<Output>
Defined in: converter/base.ts:117
Parse XML asynchronously (public API)
Parameters
Section titled “Parameters”XML string, stream, or async iterator
options?
Section titled “options?”Parse options
Returns
Section titled “Returns”Promise<Output>
Parsed output
Throws
Section titled “Throws”If parsing fails
Inherited from
Section titled “Inherited from”parseSync()
Section titled “parseSync()”parseSync(
input,options?):Output
Defined in: converter/base.ts:135
Parse XML synchronously (public API)
Parameters
Section titled “Parameters”string | ArrayBufferView<ArrayBufferLike> | Iterator<AnyXmlEvent, any, any>
XML string or sync iterator
options?
Section titled “options?”Parse options
Returns
Section titled “Returns”Output
Parsed output
Throws
Section titled “Throws”If parsing fails
Inherited from
Section titled “Inherited from”safeParse()
Section titled “safeParse()”safeParse(
input,options?):Promise<ParseResult<Output>>
Defined in: converter/base.ts:152
Parse XML asynchronously with error handling
Parameters
Section titled “Parameters”XML string, stream, or async iterator
options?
Section titled “options?”Parse options
Returns
Section titled “Returns”Promise<ParseResult<Output>>
Parse result with success flag
Inherited from
Section titled “Inherited from”safeParseSync()
Section titled “safeParseSync()”safeParseSync(
input,options?):ParseResult<Output>
Defined in: converter/base.ts:173
Parse XML synchronously with error handling
Parameters
Section titled “Parameters”string | ArrayBufferView<ArrayBufferLike> | Iterator<AnyXmlEvent, any, any>
XML string, byte view, or sync iterator
options?
Section titled “options?”Parse options
Returns
Section titled “Returns”ParseResult<Output>
Parse result with success flag
Inherited from
Section titled “Inherited from”transform()
Section titled “transform()”transform<
NewOutput>(fn):XmlSchemaBase<NewOutput,Input>
Defined in: converter/base.ts:193
Transform the parsed output
Type Parameters
Section titled “Type Parameters”NewOutput
Section titled “NewOutput”NewOutput
Parameters
Section titled “Parameters”(value) => NewOutput
Transform function
Returns
Section titled “Returns”XmlSchemaBase<NewOutput, Input>
New schema with transform applied
Inherited from
Section titled “Inherited from”optional()
Section titled “optional()”optional():
XmlSchemaBase<Output|undefined,Input|undefined>
Defined in: converter/base.ts:201
Make this schema optional
Returns
Section titled “Returns”XmlSchemaBase<Output | undefined, Input | undefined>
New optional schema
Inherited from
Section titled “Inherited from”array()
Section titled “array()”array(
xpath?):XmlSchemaBase<Output[],Input[]>
Defined in: converter/base.ts:210
Convert this schema to an array schema
Parameters
Section titled “Parameters”xpath?
Section titled “xpath?”string
XPath expression for array elements
Returns
Section titled “Returns”XmlSchemaBase<Output[], Input[]>
New array schema
Inherited from
Section titled “Inherited from”compile()
Section titled “compile()”compile():
XmlSchemaBase<Output,Input>
Defined in: converter/base.ts:238
Compile this schema for repeated parsing.
Returns
Section titled “Returns”XmlSchemaBase<Output, Input>
New compiled schema
Remarks
Section titled “Remarks”compile() preserves the public parsing API and can speed up schemas that can
be lowered to fixed XML event dispatch. The optimized path works best when the
root schema is an object, array, string, or number with static XPath selectors.
Fast-path friendly selectors use absolute paths such as /catalog/book,
descendant paths such as //book, and relative selectors inside object or
array items such as ./title, ./@id, ./name/text(), or ./name/@code.
Object fields, arrays of scalar values, arrays of objects, nested objects,
optional fields, and transforms are supported.
Selectors with wildcards or predicates, ambiguous relative paths such as
title, nested arrays, and arrays that combine an array XPath with an element
XPath are parsed with the normal runtime converter path instead. This keeps
behavior compatible, but does not get the dispatch fast path.
Call compile() once on the root schema and reuse the returned schema.
Non-object root schemas need an XPath.
Inherited from
Section titled “Inherited from”write()
Section titled “write()”write(
data,options?):Promise<string>
Defined in: converter/base.ts:249
Write data to XML string asynchronously (public API)
Parameters
Section titled “Parameters”Output
Data to write
options?
Section titled “options?”Write options
Returns
Section titled “Returns”Promise<string>
XML string
Inherited from
Section titled “Inherited from”writeToStream()
Section titled “writeToStream()”writeToStream(
data,stream,options?):Promise<void>
Defined in: converter/base.ts:272
Write data to WritableStream asynchronously (public API)
Parameters
Section titled “Parameters”Output
Data to write
stream
Section titled “stream”WritableStream<Uint8Array<ArrayBufferLike>>
Writable stream to write to
options?
Section titled “options?”Write options
Returns
Section titled “Returns”Promise<void>
Inherited from
Section titled “Inherited from”writeSync()
Section titled “writeSync()”writeSync(
data,options?):string
Defined in: converter/base.ts:286
Write data to XML string synchronously (public API)
Parameters
Section titled “Parameters”Output
Data to write
options?
Section titled “options?”Write options
Returns
Section titled “Returns”string
XML string
Inherited from
Section titled “Inherited from”writer()
Section titled “writer()”writer(
config):this
Defined in: converter/base.ts:295
Configure writer settings for this schema
Parameters
Section titled “Parameters”config
Section titled “config”Writer configuration
Returns
Section titled “Returns”this
This schema with writer config
Inherited from
Section titled “Inherited from”abstract XmlSchemaBase
Section titled “abstract XmlSchemaBase”Defined in: converter/base.ts:30
Base abstract class for all XML schema types
Remarks
Section titled “Remarks”This class provides the foundation for zod-style declarative XML parsing. Each schema type extends this class and implements the parsing logic.
Extended by
Section titled “Extended by”Type Parameters
Section titled “Type Parameters”Output
Section titled “Output”Output
Input = Output
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new XmlSchemaBase<
Output,Input>():XmlSchemaBase<Output,Input>
Returns
Section titled “Returns”XmlSchemaBase<Output, Input>
Properties
Section titled “Properties”_output
Section titled “_output”
readonly_output:Output
Defined in: converter/base.ts:31
_input
Section titled “_input”
readonly_input:Input
Defined in: converter/base.ts:32
Methods
Section titled “Methods”_parse()
Section titled “_parse()”
abstract_parse(input,options?):Output
Defined in: converter/base.ts:53
Parse XML input synchronously
Parameters
Section titled “Parameters”XML string, byte view, or sync iterator
options?
Section titled “options?”Parse options
Returns
Section titled “Returns”Output
Parsed output
Throws
Section titled “Throws”If parsing fails
_parseAsync()
Section titled “_parseAsync()”
abstract_parseAsync(input,options?):Promise<Output>
Defined in: converter/base.ts:62
Parse XML input asynchronously
Parameters
Section titled “Parameters”XML string, stream, or async iterator
options?
Section titled “options?”Parse options
Returns
Section titled “Returns”Promise<Output>
Parsed output
Throws
Section titled “Throws”If parsing fails
parse()
Section titled “parse()”parse(
input,options?):Promise<Output>
Defined in: converter/base.ts:117
Parse XML asynchronously (public API)
Parameters
Section titled “Parameters”XML string, stream, or async iterator
options?
Section titled “options?”Parse options
Returns
Section titled “Returns”Promise<Output>
Parsed output
Throws
Section titled “Throws”If parsing fails
parseSync()
Section titled “parseSync()”parseSync(
input,options?):Output
Defined in: converter/base.ts:135
Parse XML synchronously (public API)
Parameters
Section titled “Parameters”string | ArrayBufferView<ArrayBufferLike> | Iterator<AnyXmlEvent, any, any>
XML string or sync iterator
options?
Section titled “options?”Parse options
Returns
Section titled “Returns”Output
Parsed output
Throws
Section titled “Throws”If parsing fails
safeParse()
Section titled “safeParse()”safeParse(
input,options?):Promise<ParseResult<Output>>
Defined in: converter/base.ts:152
Parse XML asynchronously with error handling
Parameters
Section titled “Parameters”XML string, stream, or async iterator
options?
Section titled “options?”Parse options
Returns
Section titled “Returns”Promise<ParseResult<Output>>
Parse result with success flag
safeParseSync()
Section titled “safeParseSync()”safeParseSync(
input,options?):ParseResult<Output>
Defined in: converter/base.ts:173
Parse XML synchronously with error handling
Parameters
Section titled “Parameters”string | ArrayBufferView<ArrayBufferLike> | Iterator<AnyXmlEvent, any, any>
XML string, byte view, or sync iterator
options?
Section titled “options?”Parse options
Returns
Section titled “Returns”ParseResult<Output>
Parse result with success flag
transform()
Section titled “transform()”transform<
NewOutput>(fn):XmlSchemaBase<NewOutput,Input>
Defined in: converter/base.ts:193
Transform the parsed output
Type Parameters
Section titled “Type Parameters”NewOutput
Section titled “NewOutput”NewOutput
Parameters
Section titled “Parameters”(value) => NewOutput
Transform function
Returns
Section titled “Returns”XmlSchemaBase<NewOutput, Input>
New schema with transform applied
optional()
Section titled “optional()”optional():
XmlSchemaBase<Output|undefined,Input|undefined>
Defined in: converter/base.ts:201
Make this schema optional
Returns
Section titled “Returns”XmlSchemaBase<Output | undefined, Input | undefined>
New optional schema
array()
Section titled “array()”array(
xpath?):XmlSchemaBase<Output[],Input[]>
Defined in: converter/base.ts:210
Convert this schema to an array schema
Parameters
Section titled “Parameters”xpath?
Section titled “xpath?”string
XPath expression for array elements
Returns
Section titled “Returns”XmlSchemaBase<Output[], Input[]>
New array schema
compile()
Section titled “compile()”compile():
XmlSchemaBase<Output,Input>
Defined in: converter/base.ts:238
Compile this schema for repeated parsing.
Returns
Section titled “Returns”XmlSchemaBase<Output, Input>
New compiled schema
Remarks
Section titled “Remarks”compile() preserves the public parsing API and can speed up schemas that can
be lowered to fixed XML event dispatch. The optimized path works best when the
root schema is an object, array, string, or number with static XPath selectors.
Fast-path friendly selectors use absolute paths such as /catalog/book,
descendant paths such as //book, and relative selectors inside object or
array items such as ./title, ./@id, ./name/text(), or ./name/@code.
Object fields, arrays of scalar values, arrays of objects, nested objects,
optional fields, and transforms are supported.
Selectors with wildcards or predicates, ambiguous relative paths such as
title, nested arrays, and arrays that combine an array XPath with an element
XPath are parsed with the normal runtime converter path instead. This keeps
behavior compatible, but does not get the dispatch fast path.
Call compile() once on the root schema and reuse the returned schema.
Non-object root schemas need an XPath.
write()
Section titled “write()”write(
data,options?):Promise<string>
Defined in: converter/base.ts:249
Write data to XML string asynchronously (public API)
Parameters
Section titled “Parameters”Output
Data to write
options?
Section titled “options?”Write options
Returns
Section titled “Returns”Promise<string>
XML string
writeToStream()
Section titled “writeToStream()”writeToStream(
data,stream,options?):Promise<void>
Defined in: converter/base.ts:272
Write data to WritableStream asynchronously (public API)
Parameters
Section titled “Parameters”Output
Data to write
stream
Section titled “stream”WritableStream<Uint8Array<ArrayBufferLike>>
Writable stream to write to
options?
Section titled “options?”Write options
Returns
Section titled “Returns”Promise<void>
writeSync()
Section titled “writeSync()”writeSync(
data,options?):string
Defined in: converter/base.ts:286
Write data to XML string synchronously (public API)
Parameters
Section titled “Parameters”Output
Data to write
options?
Section titled “options?”Write options
Returns
Section titled “Returns”string
XML string
writer()
Section titled “writer()”writer(
config):this
Defined in: converter/base.ts:295
Configure writer settings for this schema
Parameters
Section titled “Parameters”config
Section titled “config”Writer configuration
Returns
Section titled “Returns”this
This schema with writer config
XmlParseError
Section titled “XmlParseError”Defined in: converter/errors.ts:6
XML parse error with detailed issue information
Extends
Section titled “Extends”Error
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new XmlParseError(
issues):XmlParseError
Defined in: converter/errors.ts:16
Parameters
Section titled “Parameters”issues
Section titled “issues”object[]
Returns
Section titled “Returns”Overrides
Section titled “Overrides”Error.constructor
Properties
Section titled “Properties”issues
Section titled “issues”issues:
object[]
Defined in: converter/errors.ts:10
List of validation issues
path:
string[]
message
Section titled “message”message:
string
code:
string
Interfaces
Section titled “Interfaces”WriterOptions
Section titled “WriterOptions”Defined in: Writer.ts:20
Configuration options for the Writer
Properties
Section titled “Properties”encoding?
Section titled “encoding?”
optionalencoding?:string
Defined in: Writer.ts:25
Text encoding for the output stream
Default Value
Section titled “Default Value”'utf-8'prettyPrint?
Section titled “prettyPrint?”
optionalprettyPrint?:boolean
Defined in: Writer.ts:31
Whether to format output with indentation
Default Value
Section titled “Default Value”falseindentString?
Section titled “indentString?”
optionalindentString?:string
Defined in: Writer.ts:37
String used for indentation when prettyPrint is true
Default Value
Section titled “Default Value”' 'addEntities?
Section titled “addEntities?”
optionaladdEntities?:object[]
Defined in: Writer.ts:43
Additional custom entities to encode
entity
Section titled “entity”entity:
string
value:
string
Default Value
Section titled “Default Value”[]autoEncodeEntities?
Section titled “autoEncodeEntities?”
optionalautoEncodeEntities?:boolean
Defined in: Writer.ts:49
Whether to automatically encode XML entities
Default Value
Section titled “Default Value”truenamespaces?
Section titled “namespaces?”
optionalnamespaces?:NamespaceDeclaration[]
Defined in: Writer.ts:55
Namespace declarations to include
Default Value
Section titled “Default Value”[]bufferSize?
Section titled “bufferSize?”
optionalbufferSize?:number
Defined in: Writer.ts:61
Internal buffer size in bytes
Default Value
Section titled “Default Value”16384highWaterMark?
Section titled “highWaterMark?”
optionalhighWaterMark?:number
Defined in: Writer.ts:67
WritableStream backpressure threshold
Default Value
Section titled “Default Value”65536flushThreshold?
Section titled “flushThreshold?”
optionalflushThreshold?:number
Defined in: Writer.ts:73
Automatic flush threshold (percentage of bufferSize)
Default Value
Section titled “Default Value”0.8enableAutoFlush?
Section titled “enableAutoFlush?”
optionalenableAutoFlush?:boolean
Defined in: Writer.ts:79
Whether to enable automatic flushing
Default Value
Section titled “Default Value”trueSyncTextSink
Section titled “SyncTextSink”Defined in: WriterSync.ts:7
Sink interface for custom sync targets.
Methods
Section titled “Methods”write()
Section titled “write()”write(
chunk):void
Defined in: WriterSync.ts:8
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”void
flush()?
Section titled “flush()?”
optionalflush():void
Defined in: WriterSync.ts:9
Returns
Section titled “Returns”void
close()?
Section titled “close()?”
optionalclose():void
Defined in: WriterSync.ts:10
Returns
Section titled “Returns”void
WriterSyncOptions
Section titled “WriterSyncOptions”Defined in: WriterSync.ts:16
Writer output options shared by string and sink variants.
Extended by
Section titled “Extended by”Properties
Section titled “Properties”encoding?
Section titled “encoding?”
optionalencoding?:string
Defined in: WriterSync.ts:17
prettyPrint?
Section titled “prettyPrint?”
optionalprettyPrint?:boolean
Defined in: WriterSync.ts:18
indentString?
Section titled “indentString?”
optionalindentString?:string
Defined in: WriterSync.ts:19
addEntities?
Section titled “addEntities?”
optionaladdEntities?:object[]
Defined in: WriterSync.ts:20
entity
Section titled “entity”entity:
string
value:
string
autoEncodeEntities?
Section titled “autoEncodeEntities?”
optionalautoEncodeEntities?:boolean
Defined in: WriterSync.ts:21
namespaces?
Section titled “namespaces?”
optionalnamespaces?:NamespaceDeclaration[]
Defined in: WriterSync.ts:22
WriterSyncSinkOptions
Section titled “WriterSyncSinkOptions”Defined in: WriterSync.ts:28
Writer options for sink-based sync mode.
Extends
Section titled “Extends”Properties
Section titled “Properties”encoding?
Section titled “encoding?”
optionalencoding?:string
Defined in: WriterSync.ts:17
Inherited from
Section titled “Inherited from”prettyPrint?
Section titled “prettyPrint?”
optionalprettyPrint?:boolean
Defined in: WriterSync.ts:18
Inherited from
Section titled “Inherited from”indentString?
Section titled “indentString?”
optionalindentString?:string
Defined in: WriterSync.ts:19
Inherited from
Section titled “Inherited from”WriterSyncOptions.indentString
addEntities?
Section titled “addEntities?”
optionaladdEntities?:object[]
Defined in: WriterSync.ts:20
entity
Section titled “entity”entity:
string
value:
string
Inherited from
Section titled “Inherited from”autoEncodeEntities?
Section titled “autoEncodeEntities?”
optionalautoEncodeEntities?:boolean
Defined in: WriterSync.ts:21
Inherited from
Section titled “Inherited from”WriterSyncOptions.autoEncodeEntities
namespaces?
Section titled “namespaces?”
optionalnamespaces?:NamespaceDeclaration[]
Defined in: WriterSync.ts:22
Inherited from
Section titled “Inherited from”bufferSize?
Section titled “bufferSize?”
optionalbufferSize?:number
Defined in: WriterSync.ts:33
Internal character buffer size.
Default Value
Section titled “Default Value”16384enableAutoFlush?
Section titled “enableAutoFlush?”
optionalenableAutoFlush?:boolean
Defined in: WriterSync.ts:39
Emit buffered chunks automatically when threshold is reached.
Default Value
Section titled “Default Value”trueflushOnClose?
Section titled “flushOnClose?”
optionalflushOnClose?:boolean
Defined in: WriterSync.ts:45
Whether to call sink.flush() when the writer is finalized.
Default Value
Section titled “Default Value”falseflushThreshold?
Section titled “flushThreshold?”
optionalflushThreshold?:number
Defined in: WriterSync.ts:52
Flush threshold (percentage or absolute char count). If <= 1, treated as percentage of bufferSize. Otherwise absolute char count.
Default Value
Section titled “Default Value”0.8ParseOptions
Section titled “ParseOptions”Defined in: converter/types.ts:10
Parse options for XML converter
Properties
Section titled “Properties”trimText?
Section titled “trimText?”
optionaltrimText?:boolean
Defined in: converter/types.ts:15
Whether to trim whitespace from text content
Default Value
Section titled “Default Value”falsedecodeEntities?
Section titled “decodeEntities?”
optionaldecodeEntities?:boolean
Defined in: converter/types.ts:21
Whether to decode XML entities
Default Value
Section titled “Default Value”truestrict?
Section titled “strict?”
optionalstrict?:boolean
Defined in: converter/types.ts:27
Strict mode for parsing
Default Value
Section titled “Default Value”falsedocumentMode?
Section titled “documentMode?”
optionaldocumentMode?:DocumentMode
Defined in: converter/types.ts:34
XML document conformance mode.
Default Value
Section titled “Default Value”'fragment'maxDepth?
Section titled “maxDepth?”
optionalmaxDepth?:number
Defined in: converter/types.ts:40
Maximum XML depth
Default Value
Section titled “Default Value”1000maxEvents?
Section titled “maxEvents?”
optionalmaxEvents?:number
Defined in: converter/types.ts:46
Maximum number of events to process
Default Value
Section titled “Default Value”1000000xpathNamespaces?
Section titled “xpathNamespaces?”
optionalxpathNamespaces?:Record<string,string>
Defined in: converter/types.ts:56
Namespace bindings used by XPath 1.0 prefix resolution.
Remarks
Section titled “Remarks”XML default namespaces do not automatically apply to unprefixed XPath element names, matching XPath 1.0 semantics. Bind a prefix here and use it in XPath expressions when selecting namespaced elements.
XmlStringOptions
Section titled “XmlStringOptions”Defined in: converter/types.ts:65
Options for string schema
Properties
Section titled “Properties”xpath?
Section titled “xpath?”
optionalxpath?:string
Defined in: converter/types.ts:69
XPath expression to locate the element
optionalmin?:number
Defined in: converter/types.ts:74
Minimum string length
optionalmax?:number
Defined in: converter/types.ts:79
Maximum string length
pattern?
Section titled “pattern?”
optionalpattern?:RegExp
Defined in: converter/types.ts:84
Regular expression pattern to validate against
XmlNumberOptions
Section titled “XmlNumberOptions”Defined in: converter/types.ts:92
Options for number schema
Properties
Section titled “Properties”xpath?
Section titled “xpath?”
optionalxpath?:string
Defined in: converter/types.ts:96
XPath expression to locate the element
optionalmin?:number
Defined in: converter/types.ts:101
Minimum value
optionalmax?:number
Defined in: converter/types.ts:106
Maximum value
optionalint?:boolean
Defined in: converter/types.ts:112
Whether the number must be an integer
Default Value
Section titled “Default Value”falseXmlObjectOptions
Section titled “XmlObjectOptions”Defined in: converter/types.ts:120
Options for object schema
Properties
Section titled “Properties”xpath?
Section titled “xpath?”
optionalxpath?:string
Defined in: converter/types.ts:124
XPath expression to locate the element
strict?
Section titled “strict?”
optionalstrict?:boolean
Defined in: converter/types.ts:130
Strict mode - reject unknown properties
Default Value
Section titled “Default Value”falseXmlElementWriteConfig
Section titled “XmlElementWriteConfig”Defined in: converter/types.ts:138
Writer configuration for XML element
Properties
Section titled “Properties”element
Section titled “element”element:
string
Defined in: converter/types.ts:142
Element name (required)
asAttribute?
Section titled “asAttribute?”
optionalasAttribute?:string
Defined in: converter/types.ts:148
Write as attribute instead of element Value is the attribute name
namespace?
Section titled “namespace?”
optionalnamespace?:object
Defined in: converter/types.ts:153
Namespace configuration
prefix?
Section titled “prefix?”
optionalprefix?:string
Namespace prefix (e.g., ‘dc’, ‘xsi’)
optionaluri?:string
Namespace URI (e.g., ‘http://purl.org/dc/elements/1.1/‘)
cdata?
Section titled “cdata?”
optionalcdata?:boolean
Defined in: converter/types.ts:169
Wrap content in CDATA section
Default Value
Section titled “Default Value”falseselfClosing?
Section titled “selfClosing?”
optionalselfClosing?:boolean
Defined in: converter/types.ts:175
Use self-closing tag for empty elements
Default Value
Section titled “Default Value”falsecomment?
Section titled “comment?”
optionalcomment?:string
Defined in: converter/types.ts:180
Add XML comment before element
XmlWriteOptions
Section titled “XmlWriteOptions”Defined in: converter/types.ts:188
Options for XML writer
Properties
Section titled “Properties”prettyPrint?
Section titled “prettyPrint?”
optionalprettyPrint?:boolean
Defined in: converter/types.ts:193
Format output with indentation
Default Value
Section titled “Default Value”falseindentString?
Section titled “indentString?”
optionalindentString?:string
Defined in: converter/types.ts:199
Indentation string
Default Value
Section titled “Default Value”' 'encoding?
Section titled “encoding?”
optionalencoding?:string
Defined in: converter/types.ts:205
Text encoding for output
Default Value
Section titled “Default Value”'utf-8'rootElement?
Section titled “rootElement?”
optionalrootElement?:string
Defined in: converter/types.ts:211
Root element name If not provided, no root element wrapper is added
namespaces?
Section titled “namespaces?”
optionalnamespaces?:object[]
Defined in: converter/types.ts:216
Global namespace declarations
prefix
Section titled “prefix”prefix:
string
uri:
string
includeDeclaration?
Section titled “includeDeclaration?”
optionalincludeDeclaration?:boolean
Defined in: converter/types.ts:225
Include XML declaration
Default Value
Section titled “Default Value”truexmlVersion?
Section titled “xmlVersion?”
optionalxmlVersion?:string
Defined in: converter/types.ts:231
XML version for declaration
Default Value
Section titled “Default Value”'1.0'writer?
Section titled “writer?”
optionalwriter?:Writer|WriterSync|WriterSyncSink
Defined in: converter/types.ts:239
Custom writer instance
- WriterSync: for writeSync() method
- WriterSyncSink: for writeSync() with custom sink
- Writer: for write() async method
StartDocumentEvent
Section titled “StartDocumentEvent”Defined in: types.ts:48
Event fired when the document starts parsing
Properties
Section titled “Properties”type:
"START_DOCUMENT"
Defined in: types.ts:49
EndDocumentEvent
Section titled “EndDocumentEvent”Defined in: types.ts:57
Event fired when the document ends parsing
Properties
Section titled “Properties”type:
"END_DOCUMENT"
Defined in: types.ts:58
StartElementEvent
Section titled “StartElementEvent”Defined in: types.ts:66
Event fired when an XML element starts
Properties
Section titled “Properties”type:
"START_ELEMENT"
Defined in: types.ts:67
name:
string
Defined in: types.ts:68
localName?
Section titled “localName?”
optionallocalName?:string
Defined in: types.ts:69
prefix?
Section titled “prefix?”
optionalprefix?:string
Defined in: types.ts:70
optionaluri?:string
Defined in: types.ts:71
attributes
Section titled “attributes”attributes:
Record<string,string>
Defined in: types.ts:72
attributesWithPrefix?
Section titled “attributesWithPrefix?”
optionalattributesWithPrefix?:Record<string,AttributeInfo>
Defined in: types.ts:73
EndElementEvent
Section titled “EndElementEvent”Defined in: types.ts:76
Properties
Section titled “Properties”type:
"END_ELEMENT"
Defined in: types.ts:77
name:
string
Defined in: types.ts:78
localName?
Section titled “localName?”
optionallocalName?:string
Defined in: types.ts:79
prefix?
Section titled “prefix?”
optionalprefix?:string
Defined in: types.ts:80
optionaluri?:string
Defined in: types.ts:81
CharactersEvent
Section titled “CharactersEvent”Defined in: types.ts:84
Properties
Section titled “Properties”type:
"CHARACTERS"
Defined in: types.ts:85
value:
string
Defined in: types.ts:86
CdataEvent
Section titled “CdataEvent”Defined in: types.ts:89
Properties
Section titled “Properties”type:
"CDATA"
Defined in: types.ts:90
value:
string
Defined in: types.ts:91
ErrorEvent
Section titled “ErrorEvent”Defined in: types.ts:94
Properties
Section titled “Properties”type:
"ERROR"
Defined in: types.ts:95
error:
Error
Defined in: types.ts:96
XmlAttribute
Section titled “XmlAttribute”Defined in: types.ts:114
Attribute interface (for Writer)
Properties
Section titled “Properties”prefix?
Section titled “prefix?”
optionalprefix?:string
Defined in: types.ts:115
localName
Section titled “localName”localName:
string
Defined in: types.ts:116
optionaluri?:string
Defined in: types.ts:117
value:
string
Defined in: types.ts:118
NamespaceDeclaration
Section titled “NamespaceDeclaration”Defined in: types.ts:125
Namespace declaration interface (for Writer) Not used in this simple implementation.
Properties
Section titled “Properties”prefix
Section titled “prefix”prefix:
string
Defined in: types.ts:126
uri:
string
Defined in: types.ts:127
ProcessingInstruction
Section titled “ProcessingInstruction”Defined in: types.ts:134
Processing instruction (PI) interface (for Writer) Not used in this simple implementation.
Properties
Section titled “Properties”target
Section titled “target”target:
string
Defined in: types.ts:135
optionaldata?:string
Defined in: types.ts:136
AttributeInfo
Section titled “AttributeInfo”Defined in: types.ts:142
Attribute information interface
Properties
Section titled “Properties”value:
string
Defined in: types.ts:143
localName
Section titled “localName”localName:
string
Defined in: types.ts:144
prefix?
Section titled “prefix?”
optionalprefix?:string
Defined in: types.ts:145
optionaluri?:string
Defined in: types.ts:146
WriteElementOptions
Section titled “WriteElementOptions”Defined in: types.ts:354
Element writing options interface (for Writer)
Properties
Section titled “Properties”prefix?
Section titled “prefix?”
optionalprefix?:string
Defined in: types.ts:355
optionaluri?:string
Defined in: types.ts:356
attributes?
Section titled “attributes?”
optionalattributes?:Record<string,string|AttributeInfo>
Defined in: types.ts:357
selfClosing?
Section titled “selfClosing?”
optionalselfClosing?:boolean
Defined in: types.ts:358
comment?
Section titled “comment?”
optionalcomment?:string
Defined in: types.ts:359
Type Aliases
Section titled “Type Aliases”XmlObjectShape
Section titled “XmlObjectShape”XmlObjectShape =
Record<string,XmlSchema<unknown,unknown>>
Defined in: converter/XmlObjectSchema.ts:42
Shape type for object schema
InferObjectOutput
Section titled “InferObjectOutput”InferObjectOutput<
T> ={ [K in keyof T]: T[K]["_output"] }
Defined in: converter/XmlObjectSchema.ts:49
Infer output type from object shape
Type Parameters
Section titled “Type Parameters”T extends XmlObjectShape
ParseInput
Section titled “ParseInput”ParseInput =
string|ArrayBufferView|ReadableStream<Uint8Array> |AsyncIterator<AnyXmlEvent> |Iterator<AnyXmlEvent>
Defined in: converter/base.ts:14
Parse input type - accepts string, sync iterator, async iterator, or ReadableStream
ParseResult
Section titled “ParseResult”ParseResult<
T> = {success:true;data:T; } | {success:false;error:XmlParseError; }
Defined in: converter/errors.ts:28
Parse result type for safe parsing operations
Type Parameters
Section titled “Type Parameters”T
Infer<
T> =T["_output"]
Defined in: converter/index.ts:108
Type Parameters
Section titled “Type Parameters”T extends XmlSchema<unknown, unknown>
SchemaType
Section titled “SchemaType”SchemaType = typeof
SchemaType[keyof typeofSchemaType]
Defined in: converter/types.ts:247
Schema type union
XmlCoreSchema
Section titled “XmlCoreSchema”XmlCoreSchema =
XmlStringSchema|XmlNumberSchema|XmlArraySchema<XmlSchemaBase<unknown,unknown>> |XmlObjectSchema<XmlObjectShape>
Defined in: converter/types.ts:277
Core schema types (non-wrapper schemas)
XmlWrappedSchema
Section titled “XmlWrappedSchema”XmlWrappedSchema =
XmlTransformSchema<unknown,unknown> |XmlOptionalSchema<XmlSchemaBase<unknown,unknown>>
Defined in: converter/types.ts:288
Wrapper schema types (transform and optional)
AnyXmlSchema
Section titled “AnyXmlSchema”AnyXmlSchema =
XmlCoreSchema|XmlWrappedSchema
Defined in: converter/types.ts:297
Any XML schema type
XmlEventType
Section titled “XmlEventType”XmlEventType = typeof
XmlEventType[keyof typeofXmlEventType]
Defined in: types.ts:6
Enumeration of XML stream event types used by the StAX parser
AnyXmlEvent
Section titled “AnyXmlEvent”AnyXmlEvent =
StartDocumentEvent|EndDocumentEvent|StartElementEvent|EndElementEvent|CharactersEvent|CdataEvent|ErrorEvent
Defined in: types.ts:102
Discriminated Union type for developer use
DocumentMode
Section titled “DocumentMode”DocumentMode =
"fragment"|"document"
Defined in: types.ts:373
XML document conformance mode.
Variables
Section titled “Variables”
constx:XmlBuilder
Defined in: converter/XmlBuilder.ts:58
Singleton builder instance
SchemaType
Section titled “SchemaType”
constSchemaType:object
Defined in: converter/types.ts:247
Schema type constants for XML schema classification
Type Declaration
Section titled “Type Declaration”STRING
Section titled “STRING”
readonlySTRING:"STRING"='STRING'
NUMBER
Section titled “NUMBER”
readonlyNUMBER:"NUMBER"='NUMBER'
readonlyARRAY:"ARRAY"='ARRAY'
OBJECT
Section titled “OBJECT”
readonlyOBJECT:"OBJECT"='OBJECT'
TRANSFORM
Section titled “TRANSFORM”
readonlyTRANSFORM:"TRANSFORM"='TRANSFORM'
OPTIONAL
Section titled “OPTIONAL”
readonlyOPTIONAL:"OPTIONAL"='OPTIONAL'
XmlEventType
Section titled “XmlEventType”
constXmlEventType:object
Defined in: types.ts:6
Enumeration of XML stream event types used by the StAX parser
Type Declaration
Section titled “Type Declaration”START_DOCUMENT
Section titled “START_DOCUMENT”
readonlySTART_DOCUMENT:"START_DOCUMENT"='START_DOCUMENT'
END_DOCUMENT
Section titled “END_DOCUMENT”
readonlyEND_DOCUMENT:"END_DOCUMENT"='END_DOCUMENT'
START_ELEMENT
Section titled “START_ELEMENT”
readonlySTART_ELEMENT:"START_ELEMENT"='START_ELEMENT'
END_ELEMENT
Section titled “END_ELEMENT”
readonlyEND_ELEMENT:"END_ELEMENT"='END_ELEMENT'
CHARACTERS
Section titled “CHARACTERS”
readonlyCHARACTERS:"CHARACTERS"='CHARACTERS'
readonlyCDATA:"CDATA"='CDATA'
readonlyERROR:"ERROR"='ERROR'
Functions
Section titled “Functions”isStringSchema()
Section titled “isStringSchema()”isStringSchema(
schema):schema is XmlStringSchema
Defined in: converter/types.ts:304
Type guard for string schema
Parameters
Section titled “Parameters”schema
Section titled “schema”XmlSchemaBase<unknown, unknown>
Returns
Section titled “Returns”schema is XmlStringSchema
isNumberSchema()
Section titled “isNumberSchema()”isNumberSchema(
schema):schema is XmlNumberSchema
Defined in: converter/types.ts:313
Type guard for number schema
Parameters
Section titled “Parameters”schema
Section titled “schema”XmlSchemaBase<unknown, unknown>
Returns
Section titled “Returns”schema is XmlNumberSchema
isArraySchema()
Section titled “isArraySchema()”isArraySchema(
schema):schema is XmlArraySchema<XmlSchemaBase<unknown, unknown>>
Defined in: converter/types.ts:322
Type guard for array schema
Parameters
Section titled “Parameters”schema
Section titled “schema”XmlSchemaBase<unknown, unknown>
Returns
Section titled “Returns”schema is XmlArraySchema<XmlSchemaBase<unknown, unknown>>
isObjectSchema()
Section titled “isObjectSchema()”isObjectSchema(
schema):schema is XmlObjectSchema<XmlObjectShape>
Defined in: converter/types.ts:331
Type guard for object schema
Parameters
Section titled “Parameters”schema
Section titled “schema”XmlSchemaBase<unknown, unknown>
Returns
Section titled “Returns”schema is XmlObjectSchema<XmlObjectShape>
isTransformSchema()
Section titled “isTransformSchema()”isTransformSchema(
schema):schema is XmlTransformSchema<unknown, unknown, unknown>
Defined in: converter/types.ts:340
Type guard for transform schema
Parameters
Section titled “Parameters”schema
Section titled “schema”XmlSchemaBase<unknown, unknown>
Returns
Section titled “Returns”schema is XmlTransformSchema<unknown, unknown, unknown>
isOptionalSchema()
Section titled “isOptionalSchema()”isOptionalSchema(
schema):schema is XmlOptionalSchema<XmlSchemaBase<unknown, unknown>>
Defined in: converter/types.ts:349
Type guard for optional schema
Parameters
Section titled “Parameters”schema
Section titled “schema”XmlSchemaBase<unknown, unknown>
Returns
Section titled “Returns”schema is XmlOptionalSchema<XmlSchemaBase<unknown, unknown>>