Contents

jaapwijnen/swift-xml-parser

A reversible XML parser powered by the excellent [swift-parsing][swift-parsing] package by [pointfree.co][pointfree]

Getting Started

var input = """

<root>
    <content attribute1="value" />
</root>
"""

// The `XMLParser` type takes a single `Bool` parameter which determines the printing mode (with or without newlines/indentation)
let xml = try XMLParser(indenting: true).parse(input)
//XML(
//    prolog: [
//        "version": "1.0", 
//        "encoding": "utf-8"
//    ], 
//    root: XML.Element(
//        name: "root", 
//        attributes: [:], 
//        content: [
//            .element(.init(name: "content", attributes: ["attribute1": "value"]))
//        ]
//    )
//)

let indentedPrintedXML = xmlParser(true).print(xml)
//
//<root>
//    <content attribute1="value"/>
//</root>

let flatPrintedXML = xmlParser(false).print(xml)
//<root><content attribute1="value"/></root>

License

This library is released under the MIT license. See LICENSE for details.

[swift-parsing]: https://github.com/pointfreeco/swift-parsing [pointfree]: https://pointfree.co

Package Metadata

Repository: jaapwijnen/swift-xml-parser

Default branch: main

README: README.md