XML SAX parser API
A SAX parser for XML that sends the events through a callback interface. SAX is the Simple API for XML, originally a Java-only API. SAX was the first widely adopted API for XML in Java, and is a de facto standard where there are versions for several programming language environments other than Java.
DATA TYPES
option()
Options used to customize the behaviour of the parser. Possible options are:
{continuation_fun, ContinuationFun}
{continuation_state, term()}
{event_fun, EventFun}
{event_state, term()}
{file_type, FileType}
FileType = normal | dtd
{encoding, Encoding}
Encoding = utf8 | {utf16,big} | {utf16,little} | latin1 | list
skip_external_dtd
event()
The SAX events that are sent to the user via the callback.
startDocument
endDocument
{startPrefixMapping, Prefix, Uri}
Prefix = string()
Uri = string()
{endPrefixMapping, Prefix}
Prefix = string()
{startElement, Uri, LocalName, QualifiedName, Attributes}
Uri = string()
LocalName = string()
QualifiedName = {Prefix, LocalName}
Prefix = string()
Attributes = [{Uri, Prefix, AttributeName, Value}]
AttributeName = string()
Value = string()
{endElement, Uri, LocalName, QualifiedName}
Uri = string()
LocalName = string()
QualifiedName = {Prefix, LocalName}
Prefix = string()
{characters, string()}
{ignorableWhitespace, string()}
{processingInstruction, Target, Data}
Target = string()
Data = string()
{comment, string()}
startCDATA
endCDATA
{startDTD, Name, PublicId, SystemId}
Name = string()
PublicId = string()
SystemId = string()
endDTD
{startEntity, SysId}
{endEntity, SysId}
{elementDecl, Name, Model}
Name = string()
Model = string()
{attributeDecl, ElementName, AttributeName, Type, Mode, Value}
ElementName = string()
AttributeName = string()
Type = string()
Mode = string()
Value = string()
{internalEntityDecl, Name, Value}
Name = string()
Value = string()
{externalEntityDecl, Name, PublicId, SystemId}
Name = string()
PublicId = string()
SystemId = string()
{unparsedEntityDecl, Name, PublicId, SystemId, Ndata}
Name = string()
PublicId = string()
SystemId = string()
Ndata = string()
{notationDecl, Name, PublicId, SystemId}
Name = string()
PublicId = string()
SystemId = string()
unicode_char()
unicode_binary()
latin1_binary()
Functions
Filename = string()
Options = [option()]
Result = {ok, EventState, Rest} |
{Tag, Location, Reason, EndTags, EventState}
Rest = unicode_binary() | latin1_binary()
Tag = atom() (fatal_error, or user defined tag)
Location = {CurrentLocation, EntityName, LineNo}
CurrentLocation = string()
EntityName = string()
LineNo = integer()
EventState = term()
Reason = term()
Parse file containing an XML document. This functions uses a default continuation function to read the file in blocks.
Xml = unicode_binary() | latin1_binary() | [unicode_char()]
Options = [option()]
Result = {ok, EventState, Rest} |
{Tag, Location, Reason, EndTags, EventState}
Rest = unicode_binary() | latin1_binary() | [unicode_char()]
Tag = atom() (fatal_error or user defined tag)
Location = {CurrentLocation, EntityName, LineNo}
CurrentLocation = string()
EntityName = string()
LineNo = integer()
EventState = term()
Reason = term()
Parse a stream containing an XML document.
CALLBACK FUNCTIONS
The callback interface is based on that the user sends a fun with the correct signature to the parser.
Functions
State = NewState = term()
NewBytes = binary() | list() (should be same as start input in stream/2)
This function is called whenever the parser runs out of input data. If the function can't get hold of more input an empty list or binary (depends on start input in stream/2) is returned. Other types of errors is handled through exceptions. Use throw/1 to send the following tuple {Tag = atom(), Reason = string()} if the continuation function encounters a fatal error. Tag is an atom that identifies the functional entity that sends the exception and Reason is a string that describes the problem.
Event = event()
Location = {CurrentLocation, Entityname, LineNo}
CurrentLocation = string()
Entityname = string()
LineNo = integer()
State = NewState = term()
This function is called for every event sent by the parser. The error handling is done through exceptions. Use throw/1 to send the following tuple {Tag = atom(), Reason = string()} if the application encounters a fatal error. Tag is an atom that identifies the functional entity that sends the exception and Reason is a string that describes the problem.