Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Kanna(鉋) is an XML/HTML parser for Swift.

License

NotificationsYou must be signed in to change notification settings

tid-kijyun/Kanna

Repository files navigation

Kanna(鉋) is an XML/HTML parser for cross-platform(macOS, iOS, tvOS, watchOS and Linux!).

It was inspired byNokogiri(鋸).

CIPlatformCocoapodCarthage compatibleSwift Package ManagerMIT License

ℹ️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 setStrict Concurrency Check toTargeted or higher.

CocoaPods

Add the following to yourPodfile:

use_frameworks!pod'Kanna','~> 5.2.2'

Carthage

Add the following to yourCartfile:

github "tid-kijyun/Kanna" ~> 5.2.2

For xcode 11.3 and earlier, the following settings are required.

  1. In the project settings add$(SDKROOT)/usr/include/libxml2 to the "header search paths" field

Swift Package Manager

  1. 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
  1. Add the following to yourPackage.swift:
// swift-tools-version:5.0import PackageDescriptionletpackage=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

  1. Add these files to your project:
    Kanna.swift
    CSS.swift
    libxmlHTMLDocument.swift
    libxmlHTMLNode.swift
    libxmlParserOption.swift
    Modules
  2. In the target settings add$(SDKROOT)/usr/include/libxml2 to theSearch Paths > Header Search Paths field
  3. In the target settings add$(SRCROOT)/Modules to theSwift Compiler - Search Paths > Import Paths field

Synopsis

import Kannalethtml="<html>...</html>"iflet doc=try?HTML(html: html, encoding:.utf8){print(doc.title)        // Search for nodes by CSSforlinkin doc.css("a, link"){print(link.text)print(link["href"])}        // Search for nodes by XPathforlinkin doc.xpath("//a | //link"){print(link.text)print(link["href"])}}
letxml="..."iflet doc=try?Kanna.XML(xml: xml, encoding:.utf8){letnamespaces=["o":"urn:schemas-microsoft-com:office:office","ss":"urn:schemas-microsoft-com:office:spreadsheet"]iflet 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.

About

Kanna(鉋) is an XML/HTML parser for Swift.

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

  •  

Packages

No packages published

Contributors37


[8]ページ先頭

©2009-2025 Movatter.jp