{"id":1741,"url":"https://github.com/tadija/AEXML","last_synced_at":"2025-08-06T13:32:22.541Z","repository":{"id":21980828,"uuid":"25305716","full_name":"tadija/AEXML","owner":"tadija","description":"Swift minion for simple and lightweight XML parsing","archived":false,"fork":false,"pushed_at":"2024-01-16T21:47:56.000Z","size":346,"stargazers_count":1032,"open_issues_count":11,"forks_count":199,"subscribers_count":40,"default_branch":"master","last_synced_at":"2025-07-22T02:37:32.635Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tadija.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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,"dei":null}},"created_at":"2014-10-16T14:21:05.000Z","updated_at":"2025-07-21T07:23:48.000Z","dependencies_parsed_at":"2022-08-07T10:01:23.455Z","dependency_job_id":"bf917e20-686a-4fc8-9993-a195a1d3db24","html_url":"https://github.com/tadija/AEXML","commit_stats":{"total_commits":207,"total_committers":30,"mean_commits":6.9,"dds":"0.21739130434782605","last_synced_commit":"38f7d00b23ecd891e1ee656fa6aeebd6ba04ecc3"},"previous_names":[],"tags_count":23,"template":false,"template_full_name":null,"purl":"pkg:github/tadija/AEXML","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tadija%2FAEXML","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tadija%2FAEXML/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tadija%2FAEXML/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tadija%2FAEXML/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tadija","download_url":"https://codeload.github.com/tadija/AEXML/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tadija%2FAEXML/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266738657,"owners_count":23976439,"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-23T02:00:09.312Z","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":[],"created_at":"2024-01-05T20:15:54.700Z","updated_at":"2025-08-06T13:32:22.152Z","avatar_url":"https://github.com/tadija.png","language":"Swift","funding_links":[],"categories":["Parsing","Libs","JSON/XML Manipulation","Data and Storage","Data Management [🔝](#readme)","Processing Libraries"],"sub_categories":["XML \u0026 HTML","Data Management","Other free courses","Libraries"],"readme":"[![Swift 5.3](https://img.shields.io/badge/Swift-5.3-orange.svg?style=flat)](https://swift.org)\n[![Platforms iOS | watchOS | tvOS | macOS](https://img.shields.io/badge/Platforms-iOS%20%7C%20watchOS%20%7C%20tvOS%20%7C%20macOS-lightgray.svg?style=flat)](http://www.apple.com)\n[![CocoaPods](https://img.shields.io/cocoapods/v/AEXML.svg?style=flat)](https://cocoapods.org/pods/AEXML)\n[![Carthage](https://img.shields.io/badge/Carthage-compatible-brightgreen.svg?style=flat)](https://github.com/Carthage/Carthage)\n[![Swift Package Manager](https://img.shields.io/badge/SPM-compatible-brightgreen.svg)](https://github.com/apple/swift-package-manager)\n[![License MIT](https://img.shields.io/badge/License-MIT-lightgrey.svg?style=flat)](https://github.com/tadija/AEXML/blob/master/LICENSE)\n\n# AEXML\n\n**Swift minion for simple and lightweight XML parsing**\n\n\u003e I made this for personal use, but feel free to use it or contribute.\n\u003e For more examples check out [Sources](Sources) and [Tests](Tests).\n\n## Index\n- [Intro](#intro)\n- [Features](#features)\n- [Usage](#usage)\n    - [Read XML](#read-xml)\n    - [Write XML](#write-xml)\n- [Installation](#installation)\n- [License](#license)\n\n## Intro\n\nThis is not a robust full featured XML parser, but rather simple, lightweight and easy to use utility for casual XML handling.\n\n## Features\n- **Read XML** data\n- **Write XML** string\n- Covered with [unit tests](https://github.com/tadija/AEXML/blob/master/Tests/AEXMLTests.swift)\n- Covered with inline docs\n\n## Usage\n\n### Read XML\nLet's say this is some XML string you picked up somewhere and made a variable `data: Data` from that.\n\n```xml\n\u003c?xml version=\"1.0\" encoding=\"utf-8\"?\u003e\n\u003canimals\u003e\n    \u003ccats\u003e\n        \u003ccat breed=\"Siberian\" color=\"lightgray\"\u003eTinna\u003c/cat\u003e\n        \u003ccat breed=\"Domestic\" color=\"darkgray\"\u003eRose\u003c/cat\u003e\n        \u003ccat breed=\"Domestic\" color=\"yellow\"\u003eCaesar\u003c/cat\u003e\n        \u003ccat\u003e\u003c/cat\u003e\n    \u003c/cats\u003e\n    \u003cdogs\u003e\n        \u003cdog breed=\"Bull Terrier\" color=\"white\"\u003eVilly\u003c/dog\u003e\n        \u003cdog breed=\"Bull Terrier\" color=\"white\"\u003eSpot\u003c/dog\u003e\n        \u003cdog breed=\"Golden Retriever\" color=\"yellow\"\u003eBetty\u003c/dog\u003e\n        \u003cdog breed=\"Miniature Schnauzer\" color=\"black\"\u003eKika\u003c/dog\u003e\n    \u003c/dogs\u003e\n\u003c/animals\u003e\n```\n\nThis is how you can use **AEXML** for working with this data:  \n(for even more examples, look at the unit tests code included in project)\n\n```swift\nguard let\n    let xmlPath = Bundle.main.path(forResource: \"example\", ofType: \"xml\"),\n    let data = try? Data(contentsOf: URL(fileURLWithPath: xmlPath))\nelse { return }\n\ndo {\n    let xmlDoc = try AEXMLDocument(xml: data, options: options)\n        \n    // prints the same XML structure as original\n    print(xmlDoc.xml)\n    \n    // prints cats, dogs\n    for child in xmlDoc.root.children {\n        print(child.name)\n    }\n    \n    // prints Optional(\"Tinna\") (first element)\n    print(xmlDoc.root[\"cats\"][\"cat\"].value)\n    \n    // prints Tinna (first element)\n    print(xmlDoc.root[\"cats\"][\"cat\"].string)\n    \n    // prints Optional(\"Kika\") (last element)\n    print(xmlDoc.root[\"dogs\"][\"dog\"].last?.value)\n    \n    // prints Betty (3rd element)\n    print(xmlDoc.root[\"dogs\"].children[2].string)\n    \n    // prints Tinna, Rose, Caesar\n    if let cats = xmlDoc.root[\"cats\"][\"cat\"].all {\n        for cat in cats {\n            if let name = cat.value {\n                print(name)\n            }\n        }\n    }\n    \n    // prints Villy, Spot\n    for dog in xmlDoc.root[\"dogs\"][\"dog\"].all! {\n        if let color = dog.attributes[\"color\"] {\n            if color == \"white\" {\n                print(dog.string)\n            }\n        }\n    }\n    \n    // prints Tinna\n    if let cats = xmlDoc.root[\"cats\"][\"cat\"].all(withValue: \"Tinna\") {\n        for cat in cats {\n            print(cat.string)\n        }\n    }\n    \n    // prints Caesar\n    if let cats = xmlDoc.root[\"cats\"][\"cat\"].all(withAttributes: [\"breed\" : \"Domestic\", \"color\" : \"yellow\"]) {\n        for cat in cats {\n            print(cat.string)\n        }\n    }\n    \n    // prints 4\n    print(xmlDoc.root[\"cats\"][\"cat\"].count)\n    \n    // prints Siberian\n    print(xmlDoc.root[\"cats\"][\"cat\"].attributes[\"breed\"]!)\n    \n    // prints \u003ccat breed=\"Siberian\" color=\"lightgray\"\u003eTinna\u003c/cat\u003e\n    print(xmlDoc.root[\"cats\"][\"cat\"].xmlCompact)\n    \n    // prints Optional(AEXML.AEXMLError.elementNotFound)\n    print(xmlDoc[\"NotExistingElement\"].error)\n}\ncatch {\n    print(\"\\(error)\")\n}\n```\n\n### Write XML\nLet's say this is some SOAP XML request you need to generate.  \nWell, you could just build ordinary string for that?\n\n```xml\n\u003c?xml version=\"1.0\" encoding=\"utf-8\"?\u003e\n\u003csoap:Envelope xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\u003e\n  \u003csoap:Header\u003e\n    \u003cm:Trans xmlns:m=\"http://www.w3schools.com/transaction/\" soap:mustUnderstand=\"1\"\u003e234\u003c/m:Trans\u003e\n  \u003c/soap:Header\u003e\n  \u003csoap:Body\u003e\n    \u003cm:GetStockPrice\u003e\n      \u003cm:StockName\u003eAAPL\u003c/m:StockName\u003e\n    \u003c/m:GetStockPrice\u003e\n  \u003c/soap:Body\u003e\n\u003c/soap:Envelope\u003e\n```\n\nYes, but, you can also do it in a more structured and elegant way with AEXML:\n\n```swift\n// create XML Document\nlet soapRequest = AEXMLDocument()\nlet attributes = [\"xmlns:xsi\" : \"http://www.w3.org/2001/XMLSchema-instance\", \"xmlns:xsd\" : \"http://www.w3.org/2001/XMLSchema\"]\nlet envelope = soapRequest.addChild(name: \"soap:Envelope\", attributes: attributes)\nlet header = envelope.addChild(name: \"soap:Header\")\nlet body = envelope.addChild(name: \"soap:Body\")\nheader.addChild(name: \"m:Trans\", value: \"234\", attributes: [\"xmlns:m\" : \"http://www.w3schools.com/transaction/\", \"soap:mustUnderstand\" : \"1\"])\nlet getStockPrice = body.addChild(name: \"m:GetStockPrice\")\ngetStockPrice.addChild(name: \"m:StockName\", value: \"AAPL\")\n\n// prints the same XML structure as original\nprint(soapRequest.xml)\n```\n\nOr perhaps like this, using result builders (see [#186](https://github.com/tadija/AEXML/pull/186)):\n\n```swift\n@AEXMLDocumentBuilder\nprivate func buildSoapEnvelope(\n    for action: String,\n    in serviceType: String,\n    with parameters: [String: String] = [:]\n) -\u003e AEXMLDocument {\n    AEXMLElement(\"s:Envelope\", attributes: [\n        \"xmlns:s\": \"http://schemas.xmlsoap.org/soap/envelope/\",\n        \"s:encodingStyle\": \"http://schemas.xmlsoap.org/soap/encoding/\"\n    ]) {\n        AEXMLElement(\"s:Body\") {\n            AEXMLElement(\"s:\\(action)\", attributes: [\n                \"xmlns:u\": serviceType\n            ]) {\n                for parameter in parameters {\n                    AEXMLElement(\n                        name: parameter.key,\n                        value: parameter.value\n                    )\n                }\n            }\n        }\n    }\n}\n```\n\n## Installation\n\n- [Swift Package Manager](https://swift.org/package-manager/):\n\n\t```swift\n    .package(url: \"https://github.com/tadija/AEXML.git\", from: \"4.7.0\")\n\t```\n\n- [Carthage](https://github.com/Carthage/Carthage):\n\n\t```ogdl\n\tgithub \"tadija/AEXML\"\n\t```\n\n- [CocoaPods](http://cocoapods.org/):\n\n\t```ruby\n\tpod 'AEXML'\n\t```\n\n## License\nAEXML is released under the MIT license. See [LICENSE](LICENSE) for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftadija%2FAEXML","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftadija%2FAEXML","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftadija%2FAEXML/lists"}