PugiSwift

0.4.1

Blazing fast XML Parser in Swift for all platforms
elihwyma/PugiSwift

What's New

v0.4.1

2024-12-08T16:42:04Z
  • Fix unsafe build flags

PugiSwift

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.

Benchmarking

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]
Loading

Example Usage

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)")
}

Description

  • Swift Tools 6.0.0
View More Packages from this Author

Dependencies

Last updated: Tue May 13 2025 16:53:21 GMT-0900 (Hawaii-Aleutian Daylight Time)