{"id":16224828,"url":"https://github.com/helje5/swiftyexpat","last_synced_at":"2025-03-19T12:30:51.022Z","repository":{"id":18662580,"uuid":"21870421","full_name":"helje5/SwiftyExpat","owner":"helje5","description":"Simple wrapper for the Expat XML parser.","archived":false,"fork":false,"pushed_at":"2021-01-05T15:36:07.000Z","size":401,"stargazers_count":9,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"develop","last_synced_at":"2025-02-28T18:42:41.486Z","etag":null,"topics":["expat-xml-parser","swift","xml-parser"],"latest_commit_sha":null,"homepage":null,"language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/helje5.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-07-15T18:09:53.000Z","updated_at":"2022-12-27T16:11:36.000Z","dependencies_parsed_at":"2022-07-16T12:54:30.577Z","dependency_job_id":null,"html_url":"https://github.com/helje5/SwiftyExpat","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/helje5%2FSwiftyExpat","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/helje5%2FSwiftyExpat/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/helje5%2FSwiftyExpat/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/helje5%2FSwiftyExpat/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/helje5","download_url":"https://codeload.github.com/helje5/SwiftyExpat/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243989576,"owners_count":20379648,"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":["expat-xml-parser","swift","xml-parser"],"created_at":"2024-10-10T12:25:49.231Z","updated_at":"2025-03-19T12:30:50.638Z","avatar_url":"https://github.com/helje5.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SwiftyExpat\n\n![Swift2](https://img.shields.io/badge/swift-2-blue.svg)\n![Swift4](https://img.shields.io/badge/swift-4-blue.svg)\n![Swift5](https://img.shields.io/badge/swift-5-blue.svg)\n![macOS](https://img.shields.io/badge/os-macOS-green.svg?style=flat)\n![tuxOS](https://img.shields.io/badge/os-tuxOS-green.svg?style=flat)\n![Travis](https://travis-ci.org/AlwaysRightInstitute/SwiftyExpat.svg?branch=develop)\n\nSimple wrapper for the Expat XML parser.\n\n### ChangeLog\n\n2019-10-04: Update to work w/ Swift 5.1 (aka Xcode 11).\n\n2018-04-27: Updated to work w/ Swift 4.0.3 (aka Xcode 9.2). Support for Swift Package Manager.\n\n2015-12-09: Updated to work w/ Swift 2.1.1 (aka Xcode 7.3?).\n\n20xx-yy-zz: Updated to work w/ Swift v0.2b5 (aka Xcode 7b5).\n\nNote: The SwiftyExpat version for Swift 1.x was using a modified Expat which\nused blocks instead of C function pointer callbacks. Swift 2 now supports C\nfunction pointer calls and hence this project got rewritten for this.\n\n### Targets\n\nThe project includes two targets:\n- SwiftyExpat\n- SwiftyExpatTests\n\n(the SPM setup has `Expat` as an own target)\n\nI suggest you start by looking at the SwiftyExpatTests.\n\n#### SwiftyExpat\n\nThis is a tiny framework wth a small Swift class to make the API nicer.\nThough this is not really necessary - Expat is reasonably easy to use from \nSwift as-is.\n\n```Swift\nlet p = Expat()\n  .onStartElement   { name, attrs in print(\"\u003c\\(name) \\(attrs)\")       }\n  .onEndElement     { name        in print(\"\u003e\\(name)\")                }\n  .onStartNamespace { prefix, uri in print(\"+NS[\\(prefix)] = \\(uri)\") }\n  .onEndNamespace   { prefix      in print(\"-NS[\\(prefix)]\")          }\n  .onError          { error       in print(\"ERROR: \\(error)\")         }\np.write(\"\u003chello\u003eworld\u003c/hello\u003e\")\np.close()\n```\n\nThe raw Expat API works like this:\n```Swift\nlet p = XML_ParserCreate(\"UTF-8\")\ndefer { XML_ParserFree(p) }\n\nXML_SetStartElementHandler(p) { _, name, attrs in\n  print(\"start tag \\(String.fromCString(name)!)\")\n}\nXML_SetEndElementHandler  (p) { _, name in\n  print(\"end tag \\(String.fromCString(name)!)\")\n}\n\nXML_Parse(p, \"\u003chello/\u003e\", 8, 0)\nXML_Parse(p, \"\", 0, 1)\n```\nYou get the idea ...\n\nNote: The closures in the raw API cannot capture variables. If you need to pass\naround context (very likely ...), you need to fill the regular Expat 'user data' \nfield (which the wrapper does, if you need an example).\n\n#### SwiftyExpatTests\n\nJust a tiny demo on how to invoke the parser.\n\n### Contact\n\n[@helje5](http://twitter.com/helje5) | helge@alwaysrightinstitute.com\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhelje5%2Fswiftyexpat","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhelje5%2Fswiftyexpat","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhelje5%2Fswiftyexpat/lists"}