GPXParser
public final class GPXParser : NSObject
extension GPXParser: XMLParserDelegate
An event-driven parser (SAX parser), currently parses GPX v1.1 files only.
This parser is already setted up, hence, does not require any handling, and will parse files directly as objects.
To get the parsed data from a GPX file, simply initialize the parser, and get the GPXRoot
from parsedData()
.
-
for parsing with
Data
typeDeclaration
Swift
public init(withData data: Data)
Parameters
data
The input must be
Data
object containing GPX markup data, and should not benil
-
for parsing with
InputStream
typeDeclaration
Swift
public init(withStream stream: InputStream)
Parameters
stream
The input must be a input stream allowing GPX markup data to be parsed synchronously
-
for parsing with
URL
typeDeclaration
Swift
public init?(withURL url: URL)
Parameters
url
The input must be a
URL
, which should point to a GPX file located at the URL given -
for parsing with a string that contains full GPX markup
Declaration
Swift
public convenience init?(withRawString string: String?)
Parameters
string
The input
String
must contain full GPX markup, which is typically contained in a.GPX
file -
for parsing with a path to a GPX file
Declaration
Swift
public convenience init?(withPath path: String)
Parameters
path
The input path, with type
String
, must contain a path that points to a GPX file used to facilitate parsing.
-
Starts parsing, returns parsed
GPXRoot
when done.Throws
GPXError
errors if an incident has occurred while midway or after parsing the GPX file.Declaration
Swift
public func fallibleParsedData(forceContinue: Bool) throws -> GPXRoot?
Parameters
forceContinue
If
true
, parser will continue parsing even if non XML-based issues like invalid coordinates have occurred -
Starts parsing, returns parsed
GPXRoot
when done.Declaration
Swift
public func legacyParsingData() -> GPXLegacyRoot?
-
Default XML Parser Delegate’s start element (
) callback. Declaration
Swift
public func parser(_ parser: XMLParser, didStartElement elementName: String, namespaceURI: String?, qualifiedName qName: String?, attributes attributeDict: [String : String] = [:])
-
Default XML Parser Delegate callback when characters are found.
Declaration
Swift
public func parser(_ parser: XMLParser, foundCharacters string: String)
-
Default XML Parser Delegate’s end element () callback.
Declaration
Swift
public func parser(_ parser: XMLParser, didEndElement elementName: String, namespaceURI: String?, qualifiedName qName: String?)
-
Handling of XML parser’s thrown error. (if there is any)
Declaration
Swift
public func parser(_ parser: XMLParser, parseErrorOccurred parseError: Error)
-
Parse GPX file, while lossy compressing it straight away, post-parsing.
Great for basic direct compression needs.
Declaration
Swift
public func lossyParsing(type: GPXCompression.lossyTypes, affecting types: [GPXCompression.lossyOptions]) -> GPXRoot?