For xcode 11.3 and earlier, the following settings are required.
In the project settings add $(SDKROOT)/usr/include/libxml2 to 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
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-comoffice",
"ss": "urn:schemas-microsoft-comspreadsheet"
]
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.
Kanna(鉋)
Kanna(鉋) is an XML/HTML parser for cross-platform(macOS, iOS, tvOS, watchOS and Linux!).
It was inspired by Nokogiri(鋸).
Features
Installation for Swift 5
CocoaPods
Add the following to your
Podfile
:Carthage
Add the following to your
Cartfile
:For xcode 11.3 and earlier, the following settings are required.
$(SDKROOT)/usr/include/libxml2
to the “header search paths” fieldSwift Package Manager
Package.swift
:Note: When a build error occurs, please try run the following command:
Manual Installation
Kanna.swift
CSS.swift
libxmlHTMLDocument.swift
libxmlHTMLNode.swift
libxmlParserOption.swift
Modules
$(SDKROOT)/usr/include/libxml2
to theSearch Paths > Header Search Paths
field$(SRCROOT)/Modules
to theSwift Compiler - Search Paths > Import Paths
fieldInstallation for swift 4
Installation for swift 3
Synopsis
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.