PugiSwift is a Swift wrapper around the C++ library pugixml. The aim is to provide a fast way to parse XML with Swift on both Apple platforms and on the server with Vapor.
The current version of pugixml bundled is 1.14.
pugixml is licensed under the MIT license and a copy can be found here.
PugiSwift has been benchmarked among other popular alterative Swift packages. The code for this benchmark is available in this repo. The test was in Release mode with the debugger turned off. Comparisons were made against Fuzi and XMLCoder.
xychart-beta
title "Parses per second of 212kb file"
x-axis "Programs" ["PugiSwift", "Fuzi", "XMLCoder"]
bar [757, 207, 54]
import Foundation
import PugiSwift
@Node struct Records {
@Attribute let value: String
@Element(childrenCodingKey: "record") let records: [Record]
}
@Node struct Record {
let name: String
let list: Int
}
let str =
"""
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<records value="Hello World">
<record>
<name>Paul Koch</name>
<list>17</list>
</record>
</records>
"""
do {
let records = try Records(from: str)
print(records)
} catch {
print("Error: \(error.localizedDescription)")
}