htmgrrrl

Types

pub type Attribute {
  Attribute(
    uri: String,
    prefix: String,
    name: String,
    value: String,
  )
}

Constructors

  • Attribute(
      uri: String,
      prefix: String,
      name: String,
      value: String,
    )

SAX events that can be emitted by the parser.

These are based off of the events found in Erlang’s xmerl_sax_parser.

pub type SaxEvent {
  StartDocument
  EndDocument
  StartPrefixMapping(prefix: String, uri: String)
  EndPrefixMapping(prefix: String)
  StartElement(
    uri: String,
    local_name: String,
    qualified_name: #(String, String),
    attributes: List(Attribute),
  )
  EndElement(
    uri: String,
    local_name: String,
    qualified_name: #(String, String),
  )
  Characters(String)
  IgnorableWhitespace(String)
  ProcessingInstruction(target: String, data: String)
  Comment(String)
  StartCdata
  EndCdata
  StartDtd(name: String, public_id: String, system_id: String)
  EndDtd
  ElementDecl(name: String, model: String)
  AttributeDeclaration(
    element_name: String,
    attribute_name: String,
    type_: String,
    mode: String,
    value: String,
  )
  InternalEntityDeclaration(name: String, value: String)
  ExternalEntityDeclaration(
    name: String,
    public_id: String,
    system_id: String,
  )
  UnparsedEntityDeclaration(
    name: String,
    public_id: String,
    system_id: String,
    notation_name: String,
  )
  NotationDeclaration(
    name: String,
    public_id: String,
    system_id: String,
  )
}

Constructors

  • StartDocument

    Receive notification of the beginning of a document. The SAX parser will send this event only once before any other event callbacks.

  • EndDocument

    Receive notification of the end of a document. The SAX parser will send this event only once, and it will be the last event during the parse.

  • StartPrefixMapping(prefix: String, uri: String)

    Begin the scope of a prefix-URI Namespace mapping. Note that start/endPrefixMapping events are not guaranteed to be properly nested relative to each other: all startPrefixMapping events will occur immediately before the corresponding startElement event, and all endPrefixMapping events will occur immediately after the corresponding endElement event, but their order is not otherwise guaranteed. There will not be start/endPrefixMapping events for the “xml” prefix, since it is predeclared and immutable.

  • EndPrefixMapping(prefix: String)

    End the scope of a prefix-URI mapping.

  • StartElement(
      uri: String,
      local_name: String,
      qualified_name: #(String, String),
      attributes: List(Attribute),
    )

    Receive notification of the beginning of an element. The Parser will send this event at the beginning of every element in the XML document; there will be a corresponding endElement event for every startElement event (even when the element is empty). All of the element’s content will be reported, in order, before the corresponding endElement event.

  • EndElement(
      uri: String,
      local_name: String,
      qualified_name: #(String, String),
    )

    Receive notification of the end of an element. The SAX parser will send this event at the end of every element in the XML document; there will be a corresponding startElement event for every endElement event (even when the element is empty).

  • Characters(String)

    Receive notification of character data.

  • IgnorableWhitespace(String)

    Receive notification of ignorable whitespace in element content.

  • ProcessingInstruction(target: String, data: String)

    Receive notification of a processing instruction. The Parser will send this event once for each processing instruction found: note that processing instructions may occur before or after the main document element.

  • Comment(String)

    Report an XML comment anywhere in the document (both inside and outside of the document element).

  • StartCdata

    Report the start of a CDATA section. The contents of the CDATA section will be reported through the regular characters event.

  • EndCdata

    Report the end of a CDATA section.

  • StartDtd(name: String, public_id: String, system_id: String)

    Report the start of DTD declarations, it’s reporting the start of the DOCTYPE declaration. If the document has no DOCTYPE declaration, this event will not be sent.

  • EndDtd

    Report the end of DTD declarations, it’s reporting the end of the DOCTYPE declaration.

  • ElementDecl(name: String, model: String)

    Report an element type declaration. The content model will consist of the string “EMPTY”, the string “ANY”, or a parenthesised group, optionally followed by an occurrence indicator. The model will be normalized so that all parameter entities are fully resolved and all whitespace is removed,and will include the enclosing parentheses. Other normalization (such as removing redundant parentheses or simplifying occurrence indicators) is at the discretion of the parser.

  • AttributeDeclaration(
      element_name: String,
      attribute_name: String,
      type_: String,
      mode: String,
      value: String,
    )

    Report an attribute type declaration.

  • InternalEntityDeclaration(name: String, value: String)

    Report an internal entity declaration.

  • ExternalEntityDeclaration(
      name: String,
      public_id: String,
      system_id: String,
    )

    Report a parsed external entity declaration.

  • UnparsedEntityDeclaration(
      name: String,
      public_id: String,
      system_id: String,
      notation_name: String,
    )

    Receive notification of an unparsed entity declaration event.

  • NotationDeclaration(
      name: String,
      public_id: String,
      system_id: String,
    )

    Receive notification of a notation declaration event.

Functions

pub fn sax(a: String, b: a, c: fn(a, Int, SaxEvent) -> a) -> Result(
  a,
  Nil,
)

Iterate over a stream of SAX events, calling the given function for each event.

The given function takes the current state, the line number of the event, and the event itself, and returns the new state. The final state is returned.

Search Document