{"id":26293699,"url":"https://github.com/chenyunguimilook/swiftyxml","last_synced_at":"2025-05-08T20:54:33.025Z","repository":{"id":56922350,"uuid":"69784430","full_name":"chenyunguiMilook/SwiftyXML","owner":"chenyunguiMilook","description":"The most swifty way to deal with XML data in swift 5.","archived":false,"fork":false,"pushed_at":"2020-10-17T09:39:45.000Z","size":111,"stargazers_count":105,"open_issues_count":5,"forks_count":28,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-04-17T10:04:41.829Z","etag":null,"topics":["carthage","cocoapod","swifty","xml","xml-data","xml-parser"],"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/chenyunguiMilook.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}},"created_at":"2016-10-02T07:21:18.000Z","updated_at":"2025-04-14T19:49:28.000Z","dependencies_parsed_at":"2022-08-21T04:50:22.413Z","dependency_job_id":null,"html_url":"https://github.com/chenyunguiMilook/SwiftyXML","commit_stats":null,"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chenyunguiMilook%2FSwiftyXML","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chenyunguiMilook%2FSwiftyXML/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chenyunguiMilook%2FSwiftyXML/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chenyunguiMilook%2FSwiftyXML/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chenyunguiMilook","download_url":"https://codeload.github.com/chenyunguiMilook/SwiftyXML/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253149380,"owners_count":21861717,"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","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":["carthage","cocoapod","swifty","xml","xml-data","xml-parser"],"created_at":"2025-03-15T02:30:05.640Z","updated_at":"2025-05-08T20:54:33.001Z","avatar_url":"https://github.com/chenyunguiMilook.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)\n\n# SwiftyXML\n\n ![Platform](https://img.shields.io/badge/platforms-iOS%208.0+%20%7C%20macOS%2010.10+%20%7C%20tvOS%209.0+%20%7C%20watchOS%202.0+-333333.svg)\n\nSwiftyXML use most swifty way to deal with XML data.\n\n## Features\n\n- [x] Infinity subscript\n- [x] dynamicMemberLookup Support (use $ started string to subscript attribute)\n- [x] Optional | Non-optional value access\n- [x] Directly access Enum type value (enums extends from RawRepresentable)\n- [x] Directly for loop in XML children nodes\n- [x] Accurate error throwing\n- [x] XML construct, formatting\n- [x] Single source file\n\nSample XML: \n\n```xml\n\u003ccatalog\u003e\n\t\u003cproduct description=\"Cardigan Sweater\" product_image=\"cardigan.jpg\" \u003e\n\t\t\u003ccatalog_item gender=\"Men's\" \u003e\n\t\t\t\u003citem_number\u003eQWZ5671\u003c/item_number\u003e\n\t\t\t\u003cprice\u003e39.95\u003c/price\u003e\n\t\t\t\u003csize description=\"Medium\" \u003e\n\t\t\t\t\u003ccolor_swatch image=\"red_cardigan.jpg\" \u003eRed\u003c/color_swatch\u003e\n\t\t\t\t\u003ccolor_swatch image=\"burgundy_cardigan.jpg\" \u003eBurgundy\u003c/color_swatch\u003e\n\t\t\t\u003c/size\u003e\n\t\t\t\u003csize description=\"Large\" \u003e\n\t\t\t\t\u003ccolor_swatch image=\"red_cardigan.jpg\" \u003eRed\u003c/color_swatch\u003e\n\t\t\t\t\u003ccolor_swatch image=\"burgundy_cardigan.jpg\" \u003eBurgundy\u003c/color_swatch\u003e\n\t\t\t\u003c/size\u003e\n\t\t\u003c/catalog_item\u003e\n\t\t\u003ccatalog_item gender=\"Women's\" \u003e\n\t\t\t\u003citem_number\u003eRRX9856\u003c/item_number\u003e\n\t\t\t\u003cprice\u003e42.50\u003c/price\u003e\n\t\t\t\u003csize description=\"Small\" \u003e\n\t\t\t\t\u003ccolor_swatch image=\"red_cardigan.jpg\" \u003eRed\u003c/color_swatch\u003e\n\t\t\t\t\u003ccolor_swatch image=\"navy_cardigan.jpg\" \u003eNavy\u003c/color_swatch\u003e\n\t\t\t\t\u003ccolor_swatch image=\"burgundy_cardigan.jpg\" \u003eBurgundy\u003c/color_swatch\u003e\n\t\t\t\u003c/size\u003e\n\t\t\u003c/catalog_item\u003e\n\t\u003c/product\u003e\n\u003c/catalog\u003e\n```\n\nWith SwiftyXML all you have to do is:\n\n```swift\nlet xml = XML(string: xmlContent)\nlet color0 = xml.product.catalog_item.size.color_swatch.1.string //\"Burgundy\"\n// notice that, we use \"$\" prefix for subscript attribute\nlet description0 = xml.product.catalog_item.size.1.$description.string //\"Large\"\n```\n\nThis is same as below, SwiftyXML will auto pick the first element as default: \n\n```swift\nlet xml = XML(data: xmlFileData)\nlet color = xml.product.0.catalog_item.0.size.0.color_swatch.1.string //return \"Burgundy\"\n```\n\nWhat about if you input some wrong keys:\n\n```swift\nlet xml = XML(data: xmlFileData)\n// print the error\nif let color1 = xml.product.catalog_item.wrong_size.wrong_color.1.xml {\n    // do stuff ~\n    print(color1)\n} else {\n    print(xml.product.catalog_item.wrong_size.wrong_color.1.error) //.product.0.catalog_item.0: no such children named: \"wrong_size\"\n}\n```\n\n## Requirements\n\n- iOS 8.0+ | macOS 10.10+ | tvOS 9.0+ | watchOS 2.0+\n- Xcode 8\n\n## Installation\n\n#### CocoaPods\nYou can use [CocoaPods](http://cocoapods.org/) to install `SwiftyXML` by adding it to your `Podfile`:\n\n```ruby\nplatform :ios, '8.0'\nuse_frameworks!\n\ntarget 'MyApp' do\n    pod 'SwiftyXML', '~\u003e 3.0.0'\nend\n```\n\n#### Carthage\nCreate a `Cartfile` that lists the framework and run `carthage update`. Follow the [instructions](https://github.com/Carthage/Carthage#if-youre-building-for-ios) to add `$(SRCROOT)/Carthage/Build/iOS/SwiftyXML.framework` to an iOS project.\n\n```\ngithub \"chenyunguiMilook/SwiftyXML\" ~\u003e 3.0.0\n```\n#### Manually\n1. Download and drop ```XML.swift``` into your project.  \n2. Congratulations!  \n\n\n#### Swift Package Manager\nYou can use [The Swift Package Manager](https://swift.org/package-manager) to install `SwiftyXML` by adding the proper description to your `Package.swift` file:\n```swift\n.package(url: \"https://github.com/chenyunguiMilook/SwiftyXML.git\", from: \"3.0.2\")\n```\n\n## Usage\n\n#### Initialization\n```swift\nimport SwiftyXML\n```\n```swift\nlet xml = XML(data: xmlFileData)\n```\n\n#### Access XML and print out the error\n\n```swift\nif let color1 = xml.product.catalog_item.wrong_size.wrong_color.1.xml {\n    // do stuff ~\n    print(color1)\n} else {\n    print(xml.product.catalog_item.wrong_size.wrong_color.1.error)\n}\n```\n\n#### Catch the error \n\n```swift\n// catch the error\ndo {\n    let color = try xml.product.catalog_item.wrong_size.wrong_color.1.getXML()\n    print(color)\n} catch {\n    print(error)\n}\n```\n\n#### Access XML List\n\n```swift\n// handle xml list\nfor catalog in xml.product.catalog_item {\n    for size in catalog.size {\n        print(size.$description.stringValue)\n    }\n}\n```\n#### Read Enums\n\n```Swift\n// read enum value, Notice: enum need implements RawRepresentable\npublic enum Color : String {\n    case Red, Navy, Burgundy\n}\n\nif let c: Color = xml.product.catalog_item.size.color_swatch.enum() {\n    print(c)\n}\n```\n\n#### Construct XML\n\n```swift\nlet store = XML(name: \"store\")\n    .addAttribute(name: \"description\", value: \"Ball Store\")\n    .addChildren([\n        // attributes can be added in the initializer\n        XML(name: \"product\", attributes: [\n            \"name\": \"football\",\n            \"weight\": 0.453\n        ])\n    ])\n\n// attributes can be added to an existing object\nlet product2 = XML(name: \"product\")\nproduct2.addAttribute(name: \"name\", value: \"basketball\")\nproduct2.addAttribute(name: \"weight\", value: 0.654)\n\n// children can be added to an existing object\nstore.addChild(product2)\n\nprint(store.toXMLString())\n```\n\n```xml\n// store xml output\n\u003cstore description=\"Ball Store\" \u003e\n\t\u003cproduct name=\"football\" weight=\"0.453\" /\u003e\n\t\u003cproduct name=\"basketball\" weight=\"0.654\" /\u003e\n\u003c/store\u003e\n```\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchenyunguimilook%2Fswiftyxml","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchenyunguimilook%2Fswiftyxml","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchenyunguimilook%2Fswiftyxml/lists"}