An open API service indexing awesome lists of open source software.

https://github.com/elihwyma/pugiswift

Blazing fast XML Parser in Swift for all platforms
https://github.com/elihwyma/pugiswift

concurrency linux swift vapor xml

Last synced: 12 months ago
JSON representation

Blazing fast XML Parser in Swift for all platforms

Awesome Lists containing this project

README

          

# PugiSwift
[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Felihwyma%2FPugiSwift%2Fbadge%3Ftype%3Dswift-versions)](https://swiftpackageindex.com/elihwyma/PugiSwift)
[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Felihwyma%2FPugiSwift%2Fbadge%3Ftype%3Dplatforms)](https://swiftpackageindex.com/elihwyma/PugiSwift)

PugiSwift is a Swift wrapper around the C++ library [pugixml](https://github.com/zeux/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](https://github.com/zeux/pugixml/releases/tag/v1.14).

pugixml is licensed under the MIT license and a copy can be found [here](Sources/pugixml/LICENSE.md).

## Benchmarking
PugiSwift has been benchmarked among other popular alterative Swift packages. The code for this benchmark is available [in this repo](https://github.com/elihwyma/PugiSwiftComparisons). The test was in Release mode with the debugger turned off. Comparisons were made against [Fuzi](https://github.com/cezheng/Fuzi.git) and [XMLCoder](https://github.com/CoreOffice/XMLCoder.git).

```mermaid
xychart-beta
title "Parses per second of 212kb file"
x-axis "Programs" ["PugiSwift", "Fuzi", "XMLCoder"]
bar [757, 207, 54]
```

## Example Usage

```swift
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 =
"""


Paul Koch
17


"""

do {
let records = try Records(from: str)
print(records)
} catch {
print("Error: \(error.localizedDescription)")
}
```