tid-kijyun/Kanna
tid-kijyun/Kanna has 2,487 GitHub stars and 222 forks. GitHot measured 0 stars in 24 hours and 0 in 7 days. Last checked 2026-11-11 09:42 UTC. Last push 2026-02-25.
Kanna(鉋) is an XML/HTML parser for Swift.
What you can do
- XPath 1.0 support for document searching
- CSS3 selector support for document searching
- Support for namespaces
- Comprehensive test suite
Measured star growth
- in 24h
- 0
- in 7 days
- 0
- in 15 days
- Update delayed
- in 1 month
- Update delayed
Net star changes over overlapping periods, not daily totals. Missing measurements are left blank. Stars measure attention, not software quality.
README.md
OriginalKanna(鉋)
Kanna(鉋) is an XML/HTML parser for cross-platform(macOS, iOS, tvOS, watchOS and Linux!).
It was inspired by Nokogiri(鋸).
:information_source: Documentation
Features
- XPath 1.0 support for document searching
- CSS3 selector support for document searching
- Support for namespaces
- Comprehensive test suite
Installation
ℹ️ If you are using Swift 6, please use Kanna 6.0.0 or later.
ℹ️ The same applies if you set Strict Concurrency Check to Targeted or higher.
CocoaPods
Add the following to your Podfile:
use_frameworks!
pod 'Kanna', '~> 5.2.2'
Carthage
Add the following to your Cartfile:
github "tid-kijyun/Kanna" ~> 5.2.2
For xcode 11.3 and earlier, the following settings are required.
- In the project settings add
$(SDKROOT)/usr/include/libxml2to the "header search paths" field
Swift Package Manager
- Installing libxml2 to your computer:
// macOS: For xcode 11.3 and earlier, the following settings are required.
$ brew install libxml2
$ brew link --force libxml2
// Linux(Ubuntu):
$ sudo apt-get install libxml2-dev
- Add the following to your
Package.swift:
// swift-tools-version:5.0
import PackageDescription
let package = Package(
name: "YourProject",
dependencies: [
.package(url: "https://github.com/tid-kijyun/Kanna.git", from: "5.2.2"),
],
targets: [
.target(
name: "YourTarget",
dependencies: ["Kanna"]),
]
)
$ swift build
Note: When a build error occurs, please try run the following command:
// Linux(Ubuntu)
$ sudo apt-get install pkg-config
Manual Installation
- Add these files to your project:
Kanna.swift
CSS.swift
libxmlHTMLDocument.swift
libxmlHTMLNode.swift
libxmlParserOption.swift
Modules - In the target settings add
$(SDKROOT)/usr/include/libxml2to theSearch Paths > Header Search Pathsfield - In the target settings add
$(SRCROOT)/Modulesto theSwift Compiler - Search Paths > Import Pathsfield
Installation for swift 4
Installation for swift 3
Synopsis
import Kanna
let html = "<html>...</html>"
if let doc = try? HTML(html: html, encoding: .utf8) {
print(doc.title)
// Search for nodes by CSS
for link in doc.css("a, link") {
print(link.text)
print(link["href"])
}
// Search for nodes by XPath
for link in doc.xpath("//a | //link") {
print(link.text)
print(link["href"])
}
}
let xml = "..."
if let doc = try? Kanna.XML(xml: xml, encoding: .utf8) {
let namespaces = [
"o": "urn:schemas-microsoft-com:office:office",
"ss": "urn:schemas-microsoft-com:office:spreadsheet"
]
if let author = doc.at_xpath("//o:Author", namespaces: namespaces) {
print(author.text)
}
}
Donation
If you like Kanna, please donate via GitHub sponsors or PayPal.
It is used to improve and maintain the library.
License
The MIT License. See the LICENSE file for more information.
Explore related projects
codecrafters-io/build-your-own-x
Master programming by recreating your favorite technologies from scratch.
562,040 starspublic-apis/public-apis
A collective list of free APIs
498,431 starsmorluto/rea
Reverse engineer anything with agents, from app behavior down to native binaries.
454,422 starsopenclaw/openclaw
The AI that really does things. Any OS. Any Platform. The lobster way. 🦞
394,406 stars