{"id":1745,"url":"https://github.com/tid-kijyun/Kanna","last_synced_at":"2025-08-06T14:31:14.038Z","repository":{"id":41284393,"uuid":"20853731","full_name":"tid-kijyun/Kanna","owner":"tid-kijyun","description":"Kanna(鉋) is an XML/HTML parser for Swift.","archived":false,"fork":false,"pushed_at":"2024-04-28T20:28:41.000Z","size":479,"stargazers_count":2420,"open_issues_count":18,"forks_count":222,"subscribers_count":44,"default_branch":"master","last_synced_at":"2024-11-28T18:39:36.852Z","etag":null,"topics":["html-parser","swift","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/tid-kijyun.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","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,"publiccode":null,"codemeta":null},"funding":{"github":["tid-kijyun"],"custom":["https://paypal.me/atsushikiwaki"]}},"created_at":"2014-06-15T11:14:38.000Z","updated_at":"2024-11-25T02:21:19.000Z","dependencies_parsed_at":"2024-06-18T11:02:30.186Z","dependency_job_id":"0e374528-ec2d-4175-a0ac-12767906653b","html_url":"https://github.com/tid-kijyun/Kanna","commit_stats":{"total_commits":258,"total_committers":42,"mean_commits":6.142857142857143,"dds":"0.18604651162790697","last_synced_commit":"41c3d28ea0eac07e4551b28def9de1ede702e739"},"previous_names":[],"tags_count":39,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tid-kijyun%2FKanna","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tid-kijyun%2FKanna/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tid-kijyun%2FKanna/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tid-kijyun%2FKanna/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tid-kijyun","download_url":"https://codeload.github.com/tid-kijyun/Kanna/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228905546,"owners_count":17989781,"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":["html-parser","swift","xml-parser"],"created_at":"2024-01-05T20:15:54.785Z","updated_at":"2025-08-06T14:31:13.989Z","avatar_url":"https://github.com/tid-kijyun.png","language":"Swift","funding_links":["https://github.com/sponsors/tid-kijyun","https://paypal.me/atsushikiwaki"],"categories":["Parsing","Libs","Swift","Network [🔝](#readme)"],"sub_categories":["XML \u0026 HTML","Network","Other free courses"],"readme":"# Kanna(鉋)\nKanna(鉋) is an XML/HTML parser for cross-platform(macOS, iOS, tvOS, watchOS and Linux!).\n\nIt was inspired by [Nokogiri](https://github.com/sparklemotion/nokogiri)(鋸).\n\n[![CI](https://github.com/tid-kijyun/Kanna/actions/workflows/ci.yml/badge.svg)](https://github.com/tid-kijyun/Kanna/actions/workflows/ci.yml)\n[![Platform](http://img.shields.io/badge/platform-ios_osx_watchos_tvos_linux-lightgrey.svg?style=flat)](https://developer.apple.com/resources/)\n[![Cocoapod](http://img.shields.io/cocoapods/v/Kanna.svg?style=flat)](http://cocoadocs.org/docsets/Kanna/)\n[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)\n[![Swift Package Manager](https://img.shields.io/badge/Swift%20Package%20Manager-compatible-brightgreen.svg)](https://github.com/apple/swift-package-manager)\n[![MIT License](http://img.shields.io/badge/license-MIT-blue.svg?style=flat)](LICENSE)\n\n:information_source: [Documentation](http://tid-kijyun.github.io/Kanna/)\n\n\n## Features\n- [x] XPath 1.0 support for document searching\n- [x] CSS3 selector support for document searching\n- [x] Support for namespaces\n- [x] Comprehensive test suite\n\n## Installation\nℹ️ If you are using Swift 6, please use Kanna 6.0.0 or later.  \nℹ️ The same applies if you set `Strict Concurrency Check` to `Targeted` or higher.\n\n#### CocoaPods\nAdd the following to your `Podfile`:\n```ruby\nuse_frameworks!\npod 'Kanna', '~\u003e 5.2.2'\n```\n\n#### Carthage\nAdd the following to your `Cartfile`:\n\n```ogdl\ngithub \"tid-kijyun/Kanna\" ~\u003e 5.2.2\n```\n\nFor xcode 11.3 and earlier, the following settings are required.\n1. In the project settings add `$(SDKROOT)/usr/include/libxml2` to the \"header search paths\" field\n\n#### Swift Package Manager\n1. Installing libxml2 to your computer:\n\n```bash\n// macOS: For xcode 11.3 and earlier, the following settings are required.\n$ brew install libxml2\n$ brew link --force libxml2\n\n// Linux(Ubuntu):\n$ sudo apt-get install libxml2-dev\n```\n\n2. Add the following to your `Package.swift`:\n\n```swift\n// swift-tools-version:5.0\nimport PackageDescription\n\nlet package = Package(\n    name: \"YourProject\",\n    dependencies: [\n        .package(url: \"https://github.com/tid-kijyun/Kanna.git\", from: \"5.2.2\"),\n    ],\n    targets: [\n        .target(\n            name: \"YourTarget\",\n            dependencies: [\"Kanna\"]),\n    ]\n)\n```\n\n```bash\n$ swift build\n```\n\n*Note: When a build error occurs, please try run the following command:*\n```bash\n// Linux(Ubuntu)\n$ sudo apt-get install pkg-config\n```\n\n#### Manual Installation\n1. Add these files to your project:  \n  [Kanna.swift](Source/Kanna.swift)  \n  [CSS.swift](Source/CSS.swift)  \n  [libxmlHTMLDocument.swift](Source/libxml/libxmlHTMLDocument.swift)  \n  [libxmlHTMLNode.swift](Source/libxml/libxmlHTMLNode.swift)  \n  [libxmlParserOption.swift](Source/libxml/libxmlParserOption.swift)  \n  [Modules](Modules)\n1. In the target settings add `$(SDKROOT)/usr/include/libxml2` to the `Search Paths \u003e Header Search Paths` field\n1. In the target settings add `$(SRCROOT)/Modules` to the `Swift Compiler - Search Paths \u003e Import Paths` field\n\n\n#### [Installation for swift 4](https://github.com/tid-kijyun/Kanna/blob/master/Documentation/InstallationForSwift4.md)\n#### [Installation for swift 3](https://github.com/tid-kijyun/Kanna/blob/master/Documentation/InstallationForSwift3.md)\n\n## Synopsis\n```swift\nimport Kanna\n\nlet html = \"\u003chtml\u003e...\u003c/html\u003e\"\n\nif let doc = try? HTML(html: html, encoding: .utf8) {\n    print(doc.title)\n    \n    // Search for nodes by CSS\n    for link in doc.css(\"a, link\") {\n        print(link.text)\n        print(link[\"href\"])\n    }\n    \n    // Search for nodes by XPath\n    for link in doc.xpath(\"//a | //link\") {\n        print(link.text)\n        print(link[\"href\"])\n    }\n}\n```\n\n```swift\nlet xml = \"...\"\nif let doc = try? Kanna.XML(xml: xml, encoding: .utf8) {\n    let namespaces = [\n                    \"o\":  \"urn:schemas-microsoft-com:office:office\",\n                    \"ss\": \"urn:schemas-microsoft-com:office:spreadsheet\"\n                ]\n    if let author = doc.at_xpath(\"//o:Author\", namespaces: namespaces) {\n        print(author.text)\n    }\n}\n```\n\n## Donation\nIf you like Kanna, please donate via GitHub sponsors or PayPal.  \nIt is used to improve and maintain the library.\n\n## License\nThe MIT License. See the LICENSE file for more information.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftid-kijyun%2FKanna","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftid-kijyun%2FKanna","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftid-kijyun%2FKanna/lists"}