Skip to content

Parser and Validator

Anirudh Ramanan edited this page Jan 22, 2020 · 1 revision

Parser

The parser is responsible for parsing the VMAP and VAST xml's and mapping them to respective models. The validator validates the VMAP / VAST model. ie ensuring the specifications are met, and all mandatory fields are present.

This entire flow is handled by the AdLoader which interacts with the network layer to fetch the xml, delegates it to the parser and the validator for further processing.

Components:

  • XmlParser: The default parser that delegates the parsing of VMAP and VAST to their respective parsers. It is a builder pattern which lets you override XmlPullParser, VMAPParser and VASTParser.

  • XmlPullParser: XmlPullParser is being used for parsing xml's.

    Why XmlPullParser:

    1. Performant way of parsing XML on Android (on average, 32 ms is spent on parsing VAST)
    2. Easy to maintain and test
  • VMAPParser: It handles the parsing of VMAP response. Since the VMAP can also contain VAST tags, this parser delegates the parsing to the VAST parser if tag is found.

  • VASTParser: It handles the parsing of VAST response.

API:

  • parse(xml: String, listener: ParserListener): The parse method expects a xml string along with the listener.

Flow:

  • The XmlParser instance is used to call the parse method with the xml string.
  • The caller has to pass the listener as a parameter so as to get notified once the parsing is done.
  • In case of success, the VMAP/VAST model is returned back as a param and in case of error, the error type and the actual error message is returned.

Error Codes: enum { PARSING_ERROR = 901, VMAP_PARSING_ERROR = 1002, VAST_PARSING_ERROR = 1004 }

Validator

API:

  • validateVMAP(data: VMAPData): Result - It validates that the values are as per the spec.

  • validateAdBreak(adBreak: AdBreak): Result - It ensures that the given ad break is valid ie it contains the time offset (cue point) and at-least one ad to play.

Once the parsing is done, the XmlValidator is used to validate the vmap model. The validator ensures all the mandatory parameters for the vmap or vast is present and is according to the specification.

Clone this wiki locally