xmerl_eventp(3)
β¨ xmerl_eventp β¨ (Erlang Module Definition)
okay so bestie, we're in the Erlang manual pages and this one is xmerl_eventp(3) β the simple event-based processors that act as little front-ends to xmerl_scan. grab a snack, this is a good one π
πΈ NAME πΈ
xmerl_eventp β simple event-based processors (front-ends to xmerl_scan).
π DESCRIPTION π
So basically it implements processing XML documents in streams for parsing in SAX style. Iconic behaviour, no cap. π
Each front-end contains more elaborate settings of xmerl_scan that makes usage of the customization functions. That's the whole vibe: it's xmerl_scan but pre-glammed with all the settings you'd want.
π¦ DATA TYPES π¦
option_list()
option_list() ::
[{atom(), term()} |
{atom(), fun(), term()} |
{atom(), fun(), fun(), term()}].
Options allow to customize the behaviour of the scanner. See also the "Customization functions" tutorial. (iykyk π )
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. (yes bestie, EOF mid-document, scary, but it's handled π«Ά){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 little goodbye moment π){rules, ReadFun, WriteFun, RulesState}|{rules, Rules}β Handles storing of scanner information when parsing.{user_state, UserState}β Global state variable accessible from all customization functions. literally the group chat everyone can read π{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. β οΈ yeah bestie, don't build new stuff on those two.{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).
xmlElement()
xmlElement() :: #xmlElement{}.
Record #xmlElement{} β that's it, that's the record. β¨
π FUNCTIONS π
file_sax(Fname, CallBackModule, UserState, Options) -> NewUserState
file_sax(Fname, CallBackModule, UserState, Options) ->
NewUserState
when
Fname :: string(),
CallBackModule :: module(),
UserState :: term(),
Options :: option_list(),
NewUserState :: term().
Parse file containing an XML document, SAX style. π
Wrapper for a call to the XML parser xmerl_scan with a hook_fun for using Xmerl export functionality directly after an entity is parsed. (so extra, so useful π
)
stream(Fname, Options) -> {xmlElement(), list()} | {error, Reason}
stream(Fname, Options) -> {xmlElement(), list()} | {error, Reason}
when
Fname :: string(),
Options :: option_list(),
Reason :: term().
Parse file containing an XML document as a stream, DOM style. π
Wrapper for a call to the XML parser xmerl_scan with a continuation_fun for handling streams of XML data.
π¨ bestie listen: thecontinuation_fun,acc_fun,fetch_fun,rulesandclose_funoptions cannot be user defined using this parser. it sets those itself, no touchy.
stream_sax(Fname, CallBackModule, UserState, Options) -> {xmerl_scan:document(), Rest} | {error, Reason}
stream_sax(Fname, CallBackModule, UserState, Options) ->
{xmerl_scan:document(), Rest} | {error, Reason}
when
Fname :: string(),
CallBackModule :: module(),
UserState :: term(),
Options :: option_list(),
Rest :: string(),
Reason :: term().
Parse file containing an XML document as a stream, SAX style. πΈ
Wrapper for a call to the XML parser xmerl_scan with a continuation_fun for handling streams of XML data.
π¨ again, important: thecontinuation_fun,acc_fun,fetch_fun,rules,hook_fun,close_funanduser_stateoptions cannot be user defined using this parser. that list is even longer than the one forstream/2, yes, we're aware π
string_sax(String, CallBackModule, UserState, Options) -> {xmerl_scan:document(), Rest} | {error, Reason}
string_sax(String, CallBackModule, UserState, Options) ->
{xmerl_scan:document(), Rest} | {error, Reason}
when
String :: list(),
CallBackModule :: module(),
UserState :: term(),
Options :: option_list(),
Rest :: string(),
Reason :: term().
Parse file containing an XML document, SAX style. π
Wrapper for a call to the XML parser xmerl_scan with a hook_fun for using Xmerl export functionality directly after an entity is parsed.
and that's the whole page, you ate it, periodt π courtesy of Ericsson AB, from xmerl 2.2, and this little corner of the docs is xmerl_eventp(3). go parse something pretty π¦β¨
π¦ 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