目录
目录README.md

swift-xml-parser

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

Getting Started

var input = """
<?xml version=\"1.0\" encoding=\"utf-8\"?>
<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)
//<?xml version=\"1.0\" encoding=\"utf-8\"?>
//<root>
//    <content attribute1="value"/>
//</root>

let flatPrintedXML = xmlParser(false).print(xml)
//<?xml version=\"1.0\" encoding=\"utf-8\"?><root><content attribute1="value"/></root>

License

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

关于
74.0 KB
邀请码
    Gitlink(确实开源)
  • 加入我们
  • 官网邮箱:gitlink@ccf.org.cn
  • QQ群
  • QQ群
  • 公众号
  • 公众号

©Copyright 2023 CCF 开源发展委员会
Powered by Trustie& IntelliDE 京ICP备13000930号