Lua library module "expat"

Author: Hans van der Meer

The Lua module expat is a C-module interfacing with the C-library Expat version 2.0.1.

Lua API accessing Expat API


  1. The calling sequences below assume the module has the name xp assigned to it from the require.
  2. Calling expat functions is in object notation with p as the variable name for the parser.

Query module state

xp.version() version of module
xp.callbacks() names of installable callbacks
xp.features() features expat was compiled with GetFeatureList

Create parser table = {name = callback, ...} ParserCreate encoding string namespace separator ParserCreateNS

Operate parser

p:parse(string[, final]) final (default false), return boolean Parse
p:stop([resumable]) resumable (default true), return boolean StopParser
p:resume() return success/failure ResumeParser

Data on the parser

p:base() get base for relative URIs in systemID GetBase
p:base(base) set base for relative URIs in systemID SetBase
p:userdata([name]) get unnamed/named userdata
p:userdata(nil/name, data) set unnamed/named userdata

Query parser state

p:status() current state of the parser GetParsingStatus
p:attributecount() attribute count on last element, index ID attribute or nil GetSpecifiedAttributeCount
p:position() current line, column, byteoffset GetCurrentByteIndex
p:inputcontext() current part of input buffer GetInputContext
p:count() byte count in current event GetCurrentByteCount
p:errormessage() nil, 0 or error, error# GetErrorCode

Parsing handlers

XML callback handlers
Nameexpat setter Nameexpat setter
XML SetXmlDeclHandler ProcessInstruction SetProcessingInstructionHandler
StartDoctype SetStartDoctypeDeclHandler EndDoctype SetEndDoctypeDeclHandler
StartElement SetStartElementHandler EndElement SetEndElementHandler
CharacterData SetCharacterDataHandler Comment SetCommentHandler
StartCDATA SetStartCdataSectionHandler EndCDATA SetEndCdataSectionHandler
Default SetDefaultHandler DefaultExpand SetDefaultHandlerExpand
StartNamespace SetStartNamespaceDeclHandler EndNamespace SetEndNamespaceDeclHandler
ExternalEntity SetExternalEntityRefHandler SkippedEntity SetSkippedEntityHandler
Element SetElementDeclHandler AttList SetAttlistDeclHandler
Entity SetEntityDeclHandler Notation SetNotationDeclHandler
UnknownEncoding SetUnknownEncodingHandler NotStandalone SetNotStandaloneHandler

XML callback handler parameters
XML parser, version, encoding, standalone ProcessInstruction parser, target, data
StartDoctype parser, name, sysid, pubid, hasdtd EndDoctype parser
StartElement parser, name, attributes EndElement parser, name
CharacterData parser, data Comment parser, data
StartCDATA parser EndCDATA parser
Default parser, string DefaultExpand parser, string
StartNamespace parser, prefix, uri EndNamespace parser, prefix
ExternalEntity parser, context, base, sysid, pubid SkippedEntity parser, name, entity
Element parser, name, model AttList parser, elname,
attname, atttype, default, required
Entity parser, name, isparam, value,
base, sysid, pubid, notate
Notation parser, name, base, sysid, pubid
Encoding parser, name, info NotStandalone parser

Other functions

p:triplet(boolean) return namespaces as separate triplet SetReturnNSTriplet
p:default() redirect handler DefaultCurrent
p:foreigndtd([false]) provide external subset DTD UseForeignDTD
p:entityparsing([nil/true/false]) always/standalone/never entities parsing SetParamEntityParsing
p:elementmodel(model) return model components Content_Type