MetarParser

public class MetarParser : NSObject, XMLParserDelegate, XMLCustomParserProtocol

The MetarParser class will parse the XML document containing METAR data and return an array of METAR objects.

This class parses the XML document in the parseDocument function and returns the array of METAR’s in a closure.

  • The variable that contains METAR XML for testing. There are three individual METAR’s used for testing.

    Declaration

    Swift

    public var sampleMETAR: String { get }
  • Initializes the new MetarParser.

    Declaration

    Swift

    public override init()

    Return Value

    A new instance of the MetarParser.

  • The completion block for the return of parsed METAR objects.

    Declaration

    Swift

    public typealias parseCompletion = (_ metar: [Any]) -> ()

    Parameters

    metar

    An array of METAR objects parsed from the XML documents

  • This function will parse the XML document and return an array of METAR obects.

    Declaration

    Swift

    public func parseDocument(_ data: Data, completion: parseCompletion)

    Parameters

    data

    Data representation of the XML document

    completion

    The completion block that returns the METAR array

  • An XMLParserDelegate function when the parser starts the XML document.

    Declaration

    Swift

    public func parserDidStartDocument(_ parser: XMLParser)

    Parameters

    parser

    The XMLParser used to parse this document.

  • An XMLParserDelegate function when the parser ends the XML document.

    Declaration

    Swift

    public func parserDidEndDocument(_ parser: XMLParser)

    Parameters

    parser

    The XMLParser used to parse this document.

  • An XMLParserDelegate function when the parser starts an element in the XML document.

    Declaration

    Swift

    public func parser(_ parser: XMLParser, didStartElement elementName: String, namespaceURI: String?, qualifiedName qName: String?, attributes attributeDict: [String : String] = [:])

    Parameters

    parser

    The XMLParser used to parse this document.

    elementName

    The name of the element that is starting.

    namespaceURI

    The namespace for this element.

    qName

    The qualified name of the element that is starting.

    attributeDict

    A [String:String] dictionary containing attribute names and attribute values.

  • An XMLParserDelegate function when the parser ends an element in the XML document.

    Declaration

    Swift

    public func parser(_ parser: XMLParser, didEndElement elementName: String, namespaceURI: String?, qualifiedName qName: String?)

    Parameters

    parser

    The XMLParser used to parse this document.

    elementName

    The name of the element that is ending.

    namespaceURI

    The namespace for this element.

    qName

    The qualified name of the element that is ending.

  • An XMLParserDelegate function when the parser finds characters in the element of the XML document.

    Declaration

    Swift

    public func parser(_ parser: XMLParser, foundCharacters string: String)

    Parameters

    parser

    The XMLParser used to parse this document.

    string

    The characters of the element.

  • An XMLParserDelegate function when the parser starts the XML document.

    Declaration

    Swift

    public func parser(_ parser: XMLParser, parseErrorOccurred parseError: Error)

    Parameters

    parser

    The XMLParser used to parse this document.

    parseError

    The Error that occurred when parsing the document.