Skip to content
This repository has been archived by the owner on Jul 23, 2020. It is now read-only.

Commit

Permalink
Updated README
Browse files Browse the repository at this point in the history
  • Loading branch information
honghaoz committed Oct 22, 2015
1 parent dda98d9 commit 392ad22
Showing 1 changed file with 52 additions and 58 deletions.
110 changes: 52 additions & 58 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,29 @@
<img src="Ji.png" width=220 alt="Ji: a Swift XML/HTML parser" />
</h3>

# Ji 戟
[![CI Status](https://travis-ci.org/honghaoz/Ji.svg?branch=master)](https://travis-ci.org/honghaoz/Ji)
[![Cocoapods Version](https://img.shields.io/cocoapods/v/Ji.svg?style=flat)](http://cocoapods.org/pods/Ji)
[![License](https://img.shields.io/cocoapods/l/Ji.svg?style=flat)](http://cocoapods.org/pods/Ji)
[![Platform](https://img.shields.io/cocoapods/p/Ji.svg?style=flat)](http://cocoapods.org/pods/Ji)
Ji 戟
=====

[![CI Status](https://travis-ci.org/honghaoz/Ji.svg?branch=master)](https://travis-ci.org/honghaoz/Ji)[![Cocoapods Version](https://img.shields.io/cocoapods/v/Ji.svg?style=flat)](http://cocoapods.org/pods/Ji)[![License](https://img.shields.io/cocoapods/l/Ji.svg?style=flat)](http://cocoapods.org/pods/Ji)[![Platform](https://img.shields.io/cocoapods/p/Ji.svg?style=flat)](http://cocoapods.org/pods/Ji)

Ji (戟) is a Swift wrapper on libxml2 for parsing XML/HTML.

## Features
- [x] Build XML/HTML Tree and Navigate
- [x] XPath Query Supported
- [x] Comprehensive Unit Test Coverage
Features
--------

- [x] Build XML/HTML Tree and Navigate
- [x] XPath Query Supported
- [x] Comprehensive Unit Test Coverage
- [ ] CSS Selector (on going)

## Requirements
Requirements
------------

- iOS 8.0+ / Mac OS X 10.9+
- Xcode 7.0
- iOS 8.0+ / Mac OS X 10.9+ / watchOS 2.0+ / tvOS 9.0+
- Xcode 7.0+

## Installation
Installation
------------

### Cocoapods

Expand All @@ -32,7 +36,7 @@ To integrate **Ji** into your Xcode project using CocoaPods, specify it in your
source 'https:/CocoaPods/Specs.git'
use_frameworks!

pod 'Ji', '~> 1.1.2'
pod 'Ji', '~> 1.2.0'
```

Then, run the following command:
Expand All @@ -46,63 +50,64 @@ $ pod install
To integrate `Ji` into your Xcode project using Carthage, specify it in your `Cartfile`:

```ogdl
github "honghaoz/Ji" >= 1.1.2
github "honghaoz/Ji" >= 1.2.0
```

### Manually

If you prefer not to use a dependency manager, you can integrate Ji into your project manually.

- Configure Xcode project:
- Open project, select the target, under **General**, in **Linked Frameworks and Libraries**, add `libxml2.2.dylib` and `libxml2.dylib`
- Under **Build Settings**, in **Header Search Paths**, add `$(SDKROOT)/usr/include/libxml2`
- Under **Build Settings**, in **Other Linker Flags**, add `-lxml2`
- Import `libxml` headers:
- Copy the those import statements:
```swift
#import <libxml/tree.h>
#import <libxml/parser.h>
#import <libxml/HTMLtree.h>
#import <libxml/HTMLparser.h>
#import <libxml/xpath.h>
#import <libxml/xpathInternals.h>
#import <libxml/xmlerror.h>
```
and paste them into your `[Modulename]-Bridging-Header.h`
- Drag `Ji.swift`, `JiHelper.swift` and `JiNode.swift` in [**Source**](https://github.com/honghaoz/Ji/tree/master/Source) folder into your project.
- Configure Xcode project:
- Open project, select the target, under **General**, in **Linked Frameworks and Libraries**, add `libxml2.2.dylib` and `libxml2.dylib`
- Under **Build Settings**, in **Header Search Paths**, add `$(SDKROOT)/usr/include/libxml2`
- Under **Build Settings**, in **Other Linker Flags**, add `-lxml2`
- Import `libxml` headers:
- Copy the those import statements:`swift
#import <libxml/tree.h>
#import <libxml/parser.h>
#import <libxml/HTMLtree.h>
#import <libxml/HTMLparser.h>
#import <libxml/xpath.h>
#import <libxml/xpathInternals.h>
#import <libxml/xmlerror.h>
` and paste them into your `[Modulename]-Bridging-Header.h`
- Drag `Ji.swift`, `JiHelper.swift` and `JiNode.swift` in [**Source**](https:/honghaoz/Ji/tree/master/Source) folder into your project.

And that's it!

## Usage
Usage
-----

> If you are using Cocoapods to integrate Ji. Import Ji first:
> ```swift
> If you are using Cocoapods to integrate Ji. Import Ji first:`swift
> import Ji
> ```
> `
- Init with `NSURL`:

- Init with `NSURL`:
```swift
let jiDoc = Ji(htmlURL: NSURL(string: "http://www.apple.com/support")!)
let titleNode = jiDoc?.xPath("//head/title")?.first
println("title: \(titleNode?.content)") // title: Optional("Official Apple Support")
```

- Init with `String`:
- Init with `String`:

```swift
let xmlString = "<?xml version='1.0' encoding='UTF-8'?><note><to>Tove</to><from>Jani</from><heading>Reminder</heading><body>Don't forget me this weekend!</body></note>"
let jiDoc = Ji(xmlString: xmlString)
let bodyNode = jiDoc?.rootNode?.firstChildWithName("body")
println("body: \(bodyNode?.content)") // body: Optional("Don\'t forget me this weekend!")
```

- Init with `NSData`:
- Init with `NSData`:

```swift
let googleIndexData = NSData(contentsOfURL: NSURL(string: "http://www.google.com")!)
if let googleIndexData = googleIndexData {
let jiDoc = Ji(htmlData: googleIndexData)!
let htmlNode = jiDoc.rootNode!
println("html tagName: \(htmlNode.tagName)") // html tagName: Optional("html")

let aNodes = jiDoc.xPath("//body//a")
if let firstANode = aNodes?.first {
println("first a node tagName: \(firstANode.name)") // first a node tagName: Optional("a")
Expand All @@ -118,26 +123,15 @@ let attribution = 戟文档?.xPath("//ul[@class='attribution']")?.first
println("作者(Author): \(attribution?.content)")
```

## License
License
-------

The MIT License (MIT)

Copyright (c) 2015 Honghao Zhang (张宏昊)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

0 comments on commit 392ad22

Please sign in to comment.