{"id":29671881,"url":"https://github.com/gottagetswifty/swiftyxmlkit","last_synced_at":"2025-07-22T20:35:52.722Z","repository":{"id":73393849,"uuid":"206493727","full_name":"GottaGetSwifty/SwiftyXMLKit","owner":"GottaGetSwifty","description":"Tools for working with XML in Swift","archived":false,"fork":false,"pushed_at":"2019-10-14T05:01:05.000Z","size":204,"stargazers_count":9,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-11-29T17:38:09.553Z","etag":null,"topics":["codable","ios","swift","xml"],"latest_commit_sha":null,"homepage":null,"language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/GottaGetSwifty.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2019-09-05T06:44:14.000Z","updated_at":"2024-06-16T07:25:57.000Z","dependencies_parsed_at":"2024-01-18T05:20:58.533Z","dependency_job_id":"816c8b0e-04dd-4fb6-98ec-fded519cf047","html_url":"https://github.com/GottaGetSwifty/SwiftyXMLKit","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/GottaGetSwifty/SwiftyXMLKit","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GottaGetSwifty%2FSwiftyXMLKit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GottaGetSwifty%2FSwiftyXMLKit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GottaGetSwifty%2FSwiftyXMLKit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GottaGetSwifty%2FSwiftyXMLKit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/GottaGetSwifty","download_url":"https://codeload.github.com/GottaGetSwifty/SwiftyXMLKit/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GottaGetSwifty%2FSwiftyXMLKit/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266568018,"owners_count":23949457,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-22T02:00:09.085Z","response_time":66,"last_error":null,"robots_txt_status":null,"robots_txt_updated_at":null,"robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["codable","ios","swift","xml"],"created_at":"2025-07-22T20:35:45.022Z","updated_at":"2025-07-22T20:35:52.711Z","avatar_url":"https://github.com/GottaGetSwifty.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SwiftyXMLKit\n\n## Availible Libraries\n\n## [SwiftyXMLCoding](#SwiftyXMLCoding): **v0.6.2(Beta)**\n\n An XMLEncoder and XMLDecoder that serializes Swift's [`Encodable`](https://developer.apple.com/documentation/swift/encodable) and [`Decodable`](https://developer.apple.com/documentation/swift/decodable) protocols to XML using `PropertyWrapper`s to indicate XML Attributes and CData Strings\n\n## Compatibility\n\nDue to the use of `PropertyWrappers`, Swift 5.1+ is required, (included in Apple's 2019 major releases). For backwards-compatible parsers I recommend [SWXMLHash](https://github.com/drmohundro/SWXMLHash) and [XMLParsing](https://github.com/ShawnMoore/XMLParsing)\n\nCurrently only Apple platforms are supported. Support for other platforms is a secondary goal.\n\n## Installation\n\n### Swift Package Manager\n\nSince SPM now has integrated support everywhere Swift 5.1 is used, there are currently no plans to support other dependency management tools. If SPM in unavailable, [Git-Submodules](https://git-scm.com/book/en/v2/Git-Tools-Submodules) is an option. More info can be found at the [SPM Website](https://swift.org/package-manager/)\n\nIf you're working directly in a Package, add SwiftyXMLKit to your Package.swift file\n\n```swift\ndependencies: [\n    .package(url: \"https://github.com/GottaGetSwifty/SwiftyXMLKit.git\", .upToNextMajor(from: \"0.6.0-beta\" )),\n]\n```\n\nIf working in an Xcode project select `File-\u003eSwift Packages-\u003eAdd Package Dependency...` and search for the package name: `SwiftyXMLKit` or the git url:\n\n`https://github.com/GottaGetSwifty/SwiftyXMLKit.git`\n\n# SwiftyXMLCoding\n\n## Example\n\n```swift\nimport SwiftyXMLCoding\n\nlet xmlStr = \"\"\"\n\u003c?xml version=\"1.0\"?\u003e\n\u003cbook id=\"bk101\"\u003e\n    \u003cauthor\u003eGambardella, Matthew\u003c/author\u003e\n    \u003cdescription\u003e\u003c![CDATA[An in-depth look \u0026 analysis of creating applications with XML.]]\u003e\u003c/description\u003e\n    \u003cgenre\u003eComputer\u003c/genre\u003e\n    \u003cprice\u003e44.95\u003c/price\u003e\n    \u003cpublish_date\u003e2000-10-01\u003c/publish_date\u003e\n    \u003ctitle\u003eXML Developer\u0026apos;s Guide\u003c/title\u003e\n\u003c/book\u003e\n\"\"\"\n\nstruct Book: Codable {\n\n    @XMLAttributeProperty\n    var id: String\n\n    var author: String\n    var title: String\n    var genre: String\n    var price: Double\n\n    @XMLCDataProperty\n    var description: String\n}\n\nfunc decodeBookXML(from data: Data) -\u003e Book? {\n    do {\n        // Verbose Decoding\n        let book = try XMLDecoder().decode(Book.self, from: xmlData)\n        return book\n        \n        // Concise Decoding:\n        return try XMLDecoder().decode(from: xmlData)\n    }\n    catch  {\n        print(error.localizedDescription)\n        return nil\n    }\n}\n\n\nfunc encodeBookAsXML(_ book: Book) -\u003e String? {}\n    do {\n         /* utf8 Data Encoding\n        let bookXMLData: Data = try XMLEncoder().encode(book, withRootKey: \"book\", header: XMLHeader(version: 1.0)\n        */\n        // String decoding\n        return try XMLEncoder().encodeAsString(book, withRootKey: \"book\", header: XMLHeader(version: 1.0)\n       \n    }\n    catch  {\n        print(error.localizedDescription)\n        return nil\n    }\n}\n```\n## Details\n\n### The Problem Being Solved\n\nMany current Swift libraries for working with XML have a more direct parsing approach. This is well suited for some use cases but heavy handed for basic XML import/export.\n\n[Codable](https://developer.apple.com/documentation/swift/codable) enables a simplified Type-level declarative API that greatly reduces the amount of boilerplate needed for serialization.\n\nUnfortunately previous to Swift 5.1 the only way to handle XML's complications like _Attributes_ was adding a way in the Serializer options to manually handle cases where a property should be mapped to an Attribute.\n\n### Solution\n\nUsing a [Property Wrapper](https://github.com/apple/swift-evolution/blob/master/proposals/0258-property-wrappers.md), this library enables the same declarative method for XML Attributes and CData Strings. These are also compatible with other Codable parsers (e.g. `JSON(En/De)coder`) allowing use of the same models for serializing XML and other formats.\n\n### Formatting Options\n\nFormatting options for `XMLEncoder` mirror [`JSONEncoder`](https://developer.apple.com/documentation/foundation/jsonencoder).\n\nFormatting options for `XMLDecoder` mirror [`JSONDecoder`](https://developer.apple.com/documentation/foundation/jsondecoder).\n\n## Future Directions/Improvements\n\n### Testing\n\nThe goal is for this to be a _tested_ and easily _testable_ library. Given the constrained nature of the approach taken a robust test suite is very achievable. The bulk of this work (encoding/decoding) is already done. Performance testing and using real-world XML is next on the list.\n\n### Other\n* Have a declarative API for encoder's \"root key\"\n* Replace other (En/De)coder options with a `PropertyWrapper`\n* Platform-agnostic Support.\n* Convert XMLDecoder to use SWXMLHash, Open up additional (simple) customization options for XMLDecoder and easier Linux support.\n* Performance Unit Tests. There are likely places where speed can be optimized, but Performance Tests should be added first to avoid unintended regression.\n* Github integration with CI pipline to automate Unit Tests for pushes and pull requests.\n* Integrate SwiftLint.\n\n## Acknowledgements\n\nThanks to the author of the project used as the seed: [XMLParsing](https://github.com/ShawnMoore/XMLParsing)! Much of it has been refactored, but it cut out a good amount of time that would've been spent wrangling Swift's `JSON(En/De)Coder` implementation to work with XML.\n\nThanks to [SWXMLHash](https://github.com/drmohundro/SWXMLHash) for handling my use cases until this was possible.\n\n# Planned Additional Library Targets\n\n## SwiftyXMLModelGenerator\n\nA tool for generating Swift Models from XML. Default format will be for compatibility with SwiftyXMLCoding.\n\n## SwiftyXMLStandards\n\nA library with simple SwiftyXMLCoding compatible implementations of standardized XML Formats, e.g. RSS, Podcasts, etc.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgottagetswifty%2Fswiftyxmlkit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgottagetswifty%2Fswiftyxmlkit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgottagetswifty%2Fswiftyxmlkit/lists"}