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
metarAn 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
dataData representation of the XML document
completionThe completion block that returns the METAR array
-
An
XMLParserDelegatefunction when the parser starts the XML document.Declaration
Swift
public func parserDidStartDocument(_ parser: XMLParser)Parameters
parserThe
XMLParserused to parse this document. -
An
XMLParserDelegatefunction when the parser ends the XML document.Declaration
Swift
public func parserDidEndDocument(_ parser: XMLParser)Parameters
parserThe
XMLParserused to parse this document. -
An
XMLParserDelegatefunction 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
parserThe
XMLParserused to parse this document.elementNameThe name of the element that is starting.
namespaceURIThe namespace for this element.
qNameThe qualified name of the element that is starting.
attributeDictA
[String:String]dictionary containing attribute names and attribute values. -
An
XMLParserDelegatefunction 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
parserThe
XMLParserused to parse this document.elementNameThe name of the element that is ending.
namespaceURIThe namespace for this element.
qNameThe qualified name of the element that is ending.
-
An
XMLParserDelegatefunction when the parser finds characters in the element of the XML document.Declaration
Swift
public func parser(_ parser: XMLParser, foundCharacters string: String)Parameters
parserThe
XMLParserused to parse this document.stringThe characters of the element.
-
An
XMLParserDelegatefunction when the parser starts the XML document.Declaration
Swift
public func parser(_ parser: XMLParser, parseErrorOccurred parseError: Error)Parameters
parserThe
XMLParserused to parse this document.parseErrorThe
Errorthat occurred when parsing the document.
MetarParser Class Reference