xmerl_scan(3)
π NAME π
xmerl_scan β single pass XML scanner. literally does the whole "read your XML in one go" thing bestie β¨
π¦ DESCRIPTION π¦
So this module is your interface to the XML parser, and it handles XML 1.0. The parser gets woken up through xmerl_scan:string/[1,2]](string/1) or [xmerl_scan:file/[1,2]. It hands you back records of the type defined in xmerl.hrl. π
Also go peek at the "Customization functions" tutorial, ok? iykyk.
πΈ DATA TYPES πΈ
document() :: xmlElement() | xmlDocument()
An XML document. π
The document that comes back from xmerl_scan:string/[1,2]](string/1) and [xmerl_scan:file/[1,2]. Which record type you actually get depends on the value of the document option you pass in. surprise mechanics, but make it XML π
global_state() :: xmerl_scanner()
The global state of the scanner, represented by the #xmerl_scanner{} record. it's giving "the scanner's whole vibe, stored" β¨
option_list() ::
[{atom(), term()} |
{atom(), fun(), term()} |
{atom(), fun(), fun(), term()}].
Options let you customize the behaviour of the scanner. Also check the "Customization functions" tutorial. π«Ά
Possible options are:
{acc_fun, Fun}β call back function to accumulate contents of entity.{continuation_fun, Fun}|{continuation_fun, Fun, ContinuationState}β call back function to decide what to do if the scanner runs into EOF before the document is complete. π{event_fun, Fun}|{event_fun, Fun, EventState}β call back function to handle scanner events.{fetch_fun, Fun}|{fetch_fun, Fun, FetchState}β call back function to fetch an external resource.{hook_fun, Fun}|{hook_fun, Fun, HookState}β call back function to process the document entities once identified.{close_fun, Fun}β called when document has been completely parsed. the finale π¬{rules, ReadFun, WriteFun, RulesState}|{rules, Rules}β handles storing of scanner information when parsing.{user_state, UserState}β global state variable accessible from all customization functions.{fetch_path, PathList}βPathListis a list of directories to search when fetching files. If the file in question is not in thefetch_path, the URI will be used as a file name.{space, Flag}βpreserve(default) to preserve spaces,normalizeto accumulate consecutive whitespace and replace it with one space. π§{line, Line}β to specify starting line for scanning in document which contains fragments of XML.{namespace_conformant, Flag}β controls whether to behave as a namespace conformant XML parser,false(default) to not, otherwisetrue.{validation, Flag}β controls whether to process as a validating XML parser:off(default) no validation, orvalidation dtdby DTD orschemaby XML Schema.falseandtrueoptions are obsolete (i.e. they may be removed in a future release), if usedfalseequalsoffandtrueequalsdtd. β οΈ{schemaLocation, [{Namespace,Link}|...]}β tells explicitly which XML Schema documents to use to validate the XML document. Used together with the{validation,schema}option.{quiet, Flag}β set totrueif Xmerl should behave quietly and not output any information to standard output (defaultfalse).{doctype_DTD, DTD}β allows to specify DTD name when it isn't available in the XML document. This option has effect only together with{validation,dtd}option.{xmlbase, Dir}β XML Base directory. If usingstring/1default is current directory. If usingfile/1default is directory of given file.{encoding, Enc}β set default character set used (defaultUTF-8). This character set is used only if not explicitly given by the XML declaration.{document, Flag}β set totrueif Xmerl should return a complete XML document as anxmlDocumentrecord (defaultfalse).{comments, Flag}β set tofalseif Xmerl should skip comments, otherwise they will be returned asxmlCommentrecords (defaulttrue).{default_attrs, Flag}β set totrueif Xmerl should add to elements missing attributes with a defined default value (defaultfalse).{allow_entities, Flag}β set totrueifxmerl_scanshouldn't fail when there is anENTITYdeclaration in the XML document (defaultfalse).
xmlDocument() :: xmerl:xmlDocument()
Record #xmlDocument{}. π
The record definition is found in xmerl.hrl.
xmlElement() :: xmerl:xmlElement()
Record #xmlElement{}. π§©
The record definition is found in xmerl.hrl.
β¨ FUNCTIONS β¨
accumulate_whitespace(Text, global_state(), How, Acc) -> {NewAcc, NewText, global_state()}
when
Text :: string(),
How :: preserve | normalize,
Acc :: string(),
NewAcc :: string(),
NewText :: string().
Accumulate and normalize whitespace. the space girlie π¬οΈ
cont_state(global_state()) -> ContinuationState
when ContinuationState :: term().
Fetch the ContinuationState.
See the "Customization functions" tutorial.
cont_state(ContState :: term(), global_state()) -> global_state()
Set the ContinuationState, to be used in a continuation function.
The continuation function is called when the parser encounters the end of the byte stream. See the "Customization functions" tutorial.
event_state(global_state()) -> EventState
when EventState :: term().
Fetch the EventState.
See the "Customization functions" tutorial.
event_state(EventState :: term(), global_state()) -> global_state()
Set the EventState, to be used in an event function.
The event function is called at the beginning and at the end of a parsed entity. See the "Customization functions" tutorial. π
fetch_state(global_state()) -> FetchState
when FetchState :: term().
Fetch the FetchState.
See the "Customization functions" tutorial.
fetch_state(FetchState :: term(), global_state()) -> global_state()
Set the FetchState, to be used in a fetch function.
The fetch function is and called when the parser fetches an external resource (eg. a DTD). See the "Customization functions" tutorial.
file(Filename :: string(), option_list()) -> {dynamic(), Rest} | {error, Reason}
when Rest :: string(), Reason :: term().
Parse a file containing an XML document π
hook_state(global_state()) -> HookState
when HookState :: term().
Fetch the HookState.
See the "Customization functions" tutorial.
hook_state(HookState :: term(), global_state()) -> global_state()
Set the HookState, to be used in a hook function.
The hook function is and called when the parser has parsed a complete entity. See the "Customization functions" tutorial. πͺ
rules_state(global_state()) -> RulesState
when RulesState :: term().
Fetch the RulesState.
See the "Customization functions" tutorial.
rules_state(RulesState :: term(), global_state()) -> global_state()
Set the RulesState, to be used in a rules function.
The rules function is and called when the parser store scanner information in a rules database. See the "Customization functions" tutorial.
string(Text :: string(), option_list()) -> {dynamic(), Rest}
when Rest :: string().
Parse a string containing an XML document π§΅β¨
user_state(global_state()) -> UserState
when UserState :: term().
Fetch the UserState.
See the "Customization functions" tutorial.
user_state(UserState :: term(), G :: global_state()) -> global_state()
Set the UserState, to be used in a user function.
See the "Customization functions" tutorial. π
okay that's the whole page, no notes, nothing skipped, we ate and left no crumbs π
Ericsson AB made this, it's part of xmerl 2.2, and this whole page is literally xmerl_scan(3). take care of her bestie πππ¦
π¦ where this page comes from
- nixos 26.05: erlang 29.1.2
- nixpkgs unstable: erlang 29.1.2
- ubuntu stonking: erlang-doc 1:29.0.6+dfsg-1 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms