Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/Mozharovsky/XMLParser

A lightweight XMLParser for assembling and parsing XML values written for iOS 8+ in Swift 2.
https://github.com/Mozharovsky/XMLParser

Last synced: 9 days ago
JSON representation

A lightweight XMLParser for assembling and parsing XML values written for iOS 8+ in Swift 2.

Awesome Lists containing this project

README

        



Overview
==========
* [Description](https://github.com/Mozharovsky/XMLParser#description)
* [Requirements](https://github.com/Mozharovsky/XMLParser#requirements)
* [Installation](https://github.com/Mozharovsky/XMLParser#installation)
* [Usage](https://github.com/Mozharovsky/XMLParser#usage)
* [Author](https://github.com/Mozharovsky/XMLParser#author)
* [License](https://github.com/Mozharovsky/XMLParser#license)

Description
==========
XMLParser lets you convert a pure Swift dictionary into XML string and vice versa.

Requirements
==========
* Swift 2 (Xcode 7+)
* iOS 8+
* ARC

Installation
==========

###Cocoa Pods
```ruby
pod 'XMLParser', '~> 1.0'
```

Usage
==========

####Parsing an XML string from a Dictionary
```swift
let body = [
"request" : [
"meta" : [
"type" : "getOrder",
"date" : "2015-08-29 12:00:00",
"device_name" : "iPhone 6 Plus",
"device_os_version" : "iOS 9"
]
],

"encryption" : [
"type" : "RSA"
]
]

let header = "\n"
let result = XMLParser.sharedParser.encode(body, header: header)
print(result)
```

####Result
```XML

RSA


getOrder
iOS 9
2015-08-29 12:00:00
iPhone 6 Plus

```

####Associated tags
E.g. `0`
```swift
let data = [
"tr" : [
XMLTag(header: "td", name: "class", value: "num") : 1,
XMLTag(header: "td", name: "class", value: "achievments") : 0,
XMLTag(header: "td", name: "class", value: "sum") : 205
]
]

let result = XMLParser.sharedParser.encode(data)
print(result)
```

####Result
```XML

0
1
205

```

==========

####Extracting data from an XML converted string
```swift
let convertedString = "getOrder2015-08-29 12:00:00iPhone 6 PlusiOS 9RSA"
let result = XMLParser.sharedParser.decode(convertedString)
print(result)
```

####Result
```swift
[
type: [getOrder, RSA],
device_os_version: [iOS 9],
date: [2015-08-29 12:00:00],
device_name: [iPhone 6 Plus]
]
```

Author
==========
Eugene Mozharovsky ([@DottieYottie](https://twitter.com/DottieYottie))

[License](https://github.com/Mozharovsky/XMLParser/blob/master/LICENSE)
==========