Compatibility
- 1.0.05.35.25.15.04.2
- master5.35.25.15.04.2
- 1.0.0iOSmacOS(Intel)macOS(ARM)LinuxtvOSwatchOS
- masteriOSmacOS(Intel)macOS(ARM)LinuxtvOSwatchOS
A lightweight xml parser written in pure swift
Lightweight XML parsing in pure Swift 4. No Foundation. No dependencies.
SwiftXML is an event-driven XML parser intended to replace the Foundation (NS
)XMLParser
class. SwiftXML works on Linux. SwiftXML doesn’t wrap anything. It parses XML directly, character by character. And the API is simple and easy to use:
protocol XMLParser
{
mutating
func handle_data(data:[Unicode.Scalar])
mutating
func handle_tag_start(name:String, attributes:[String: String])
mutating
func handle_tag_empty(name:String, attributes:[String: String])
mutating
func handle_tag_end(name:String)
mutating
func handle_processing_instruction(target:String, data:[Unicode.Scalar])
mutating
func handle_error(_ message:String, line:Int, column:Int)
}
extension XMLParser
{
mutating
func parse(_ str:String)
mutating
func parse(path:String)
}
Import the package with
import XML
Supported XML features:
<
, >
, '
, "
, &
) in text data<
, >
, '
, "
, &
) in attribute dataCDATA
sectionsSwiftXML will tokenize your XML string into tags and data. It does not build any tree structures.
See the tests.swift
file for a usage example.