Skip to content

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

License

Notifications You must be signed in to change notification settings

abhinavdimri/Kanna

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

93 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Kanna(鉋)

Kanna(鉋) is an XML/HTML parser for MacOSX/iOS. (formerly Swift-HTML-Parser)

It was inspired by Nokogiri(鋸).

License Platform Language Issues Cocoapod Carthage compatible Reference Status

Features:

  • XPath 1.0 support for document searching
  • CSS3 selector support for document searching
  • Support for namespace
  • Comprehensive test suite

Installation:

Swift2

#####Cocoapods Adding it to your Podfile:

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

#####Carthage Adding it to your Cartfile:

github "tid-kijyun/Kanna" ~> 1.0.0
  1. In the project settings add $(SDKROOT)/usr/include/libxml2 to the "header search paths" field

#####Munually

  1. Add files to your project:
    Kanna.swift
    CSS.swift
    libxmlHTMLDocument.swift
    libxmlHTMLNode.swift
    libxmlParserOption.swift
  2. Copy folder to your project:
    Modules
  3. In the project settings add $(SRCROOT)/YOUR_PROJECT/Modules to the "Swift Compiler - Search Paths > Import Paths" field

Note: For manually, this library don't need import and namespace in your code.

Synopsis:

import Kanna

let html = "<html>...</html>"

if let doc = Kanna.HTML(html: html, encoding: NSUTF8StringEncoding) {
    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 = Kanna.XML(xml: xml, encoding: NSUTF8StringEncoding) {
    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)
    }
}

Lisense:

The MIT License. See the LICENSE file for more infomation.

About

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

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Swift 89.9%
  • HTML 5.3%
  • Objective-C 3.1%
  • Ruby 1.7%