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

Related tags

Graphics XMLParser
Overview

Overview

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

pod 'XMLParser', '~> 1.0'

Usage

####Parsing an XML string from a Dictionary

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 = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
let result = XMLParser.sharedParser.encode(body, header: header)
print(result)

####Result

<?xml version="1.0" encoding="UTF-8"?>
<encryption>
   <type>RSA</type>
</encryption>
<request>
   <meta>
      <type>getOrder</type>
      <device_os_version>iOS 9</device_os_version>
      <date>2015-08-29 12:00:00</date>
      <device_name>iPhone 6 Plus</device_name>
   </meta>
</request>

####Associated tags E.g. <td class='achievements'>0</td>

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

<tr>
   <td class='achievments'>0</td>
   <td class='num'>1</td>
   <td class='sum'>205</td>
</tr>

==========

####Extracting data from an XML converted string

let convertedString = "<request><meta><type>getOrder</type><date>2015-08-29 12:00:00</date><device_name>iPhone 6 Plus</device_name><device_os_version>iOS 9</device_os_version></meta></request><encryption><type>RSA</type></encryption>"
let result = XMLParser.sharedParser.decode(convertedString)
print(result)

####Result

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

Author

Eugene Mozharovsky (@DottieYottie)

License

Comments
  • xml hierarchy not parsed correctly

    xml hierarchy not parsed correctly

    The XML below will be parsed to 1 dictionary with 4 values. The first is location, the 2nd is conditions with 4 values, the third is day with 3 values and the 4th is temperature with 3 values.

    I would have expected a dictionary with 2 values where the 2nd value would be the forecast with an array of 3 objects which each on its own would have been a dictionary with 3 values.

    <location>Toronto, Canada</location>
    <three_day_forecast>
        <forecast>
            <conditions>Partly cloudy</conditions>
            <day>Monday</day>
            <temperature>20</temperature>
        </forecast>
        <forecast>
            <conditions>Showers</conditions>
            <day>Tuesday</day>
            <temperature>22</temperature>
        </forecast>
        <forecast>
            <conditions>Sunny</conditions>
            <day>Wednesday</day>
            <temperature>28</temperature>
        </forecast>
    </three_day_forecast>
    
    bug 
    opened by evermeer 0
  • Add support for OSX

    Add support for OSX

    Since you are only using Foundation it should work fine on OS X and even WatchOS

    please replace your s.platform in your .podspec by: s.ios.deployment_target = '8.0' s.osx.deployment_target = '10.9' s.watchos.deployment_target = '2.0'

    enhancement 
    opened by evermeer 0
  • Correct the spelling of CocoaPods in README

    Correct the spelling of CocoaPods in README

    This pull requests corrects the spelling of CocoaPods 🤓 https://github.com/CocoaPods/shared_resources/tree/master/media

    Created with cocoapods-readme.

    opened by ReadmeCritic 0
  • XMLParser v1.1

    XMLParser v1.1

    Changes

    2 tasks

    • [ ] Parse XML data hierarchy into arrays with dictionaries (#4)
    • [ ] Direct reading from a file
    • [ ] Support for web parsing (advanced asynchronous operations)
    • [ ] Unit Tests
    • [ ] 100% documentation
    enhancement v1.1 
    opened by mozharovsky 0
  • More advanced XML parsing

    More advanced XML parsing

    Advanced XML features

    • [ ] Read and parse arrays in the provided dictionary
    • [ ] Recognize associated headers (*2)
    • [x] Encode associated headers (*3)
    • [ ] Update CocoaPods and Demo project
    *2
    <tr>
        <td class='num'>1</td>
        <td class='achievments'>0</td>
        <td class='sum'>205</td>
    </tr>
    
    *3
    let data = [
        XMLTag(header: "td", name: "class", value: "num") : 1,
        XMLTag(header: "td", name: "class", value: "achievments") : 0,
        XMLTag(header: "td", name: "class", value: "sum") : 205
    ]
    
    enhancement v1.1 
    opened by mozharovsky 0
Releases(1.0)
Owner
Eugene Mozharovsky
Eugene Mozharovsky
A super easy way to check if the installed app has an update available. It is built with simplicity and customisability in mind and comes with pre-written tests.

UpdateAvailableKit This is UpdateAvailableKit: a super easy way to check if the installed app has an update available. It is built with simplicity and

Swapnanil Dhol 22 Jan 5, 2023
Conical (angular) gradient for iOS written in Swift

AEConicalGradient Conical (angular) gradient in Swift I hope that somebody will find this useful. And nice. Usage AEConicalGradient is a minion which

Marko Tadić 82 Dec 27, 2022
SVG parser and renderer written in SwiftUI

SVGView SVG parser written in SwiftUI We are a development agency building phenomenal apps. Overview The goal of this project is to bring the full pow

Exyte 269 Jan 4, 2023
QEMU-Manager is a macOS graphical frontend to QEMU, written in Swift.

QEMU-Manager About QEMU-Manager is a macOS graphical frontend to QEMU, written in Swift. Screenshots General Configuration: Hardware Configuration: Di

Jean-David Gadina 212 Jan 6, 2023
Drawing and Geometry made easy on iOS - now in Swift 3.0

InkKit Swift Support Swift 4.0 InkKit is Swift 4.0 by default, so to use that just include InkKit in your podfile: pod 'InkKit' Swift 3.2 In order to

Shaps 373 Dec 27, 2022
iOS utility classes for asynchronous rendering and display.

YYAsyncLayer iOS utility classes for asynchronous rendering and display. (It was used by YYText) Simple Usage @interface YYLabel : UIView @property NS

null 672 Dec 27, 2022
An iOS framework for easily adding drawings and text to images.

jot is an easy way to add touch-controlled drawings and text to images in your iOS app. What's jot for? Annotating Images jot is the easiest way to ad

IFTTT 1.8k Oct 28, 2022
Display and interact with SVG Images on iOS / OS X, using native rendering (CoreAnimation)

SVGKit SVGKit is a Cocoa framework for rendering SVG files natively: it's fast and powerful. Some additional info and links are on the wiki Versions:

null 4.3k Jan 3, 2023
The application is develop in Objective IOS. kids can draw whatever they want and also kids can save the drawing as well as undo erase the drawing.

IOSObjC_KidsBoard The application is develop in Objective IOS. kids can draw whatever they want and also kids can save the drawing as well as undo era

Haresh 0 Oct 28, 2021
Powerful and easy-to-use vector graphics Swift library with SVG support

Macaw Powerful and easy-to-use vector graphics Swift library with SVG support We are a development agency building phenomenal apps. What is Macaw? Mac

Exyte 5.9k Jan 2, 2023
NXDrawKit is a simple and easy but useful drawing kit for iPhone

⚠️ To use with Swift 5.0 please ensure you are using >= 0.8.0 ⚠️ ⚠️ To use with Swift 4.2 please ensure you are using >= 0.7.1 ⚠️ ⚠️ To use with Swift

Nicejinux 1.3k Dec 31, 2022
Create gradients and blur gradients without a single line of code

EZYGradientView is a different and unique take on creating gradients and gradients with blur on the iOS platform. The default CAGradientLayer implemen

Shashank Pali 380 Dec 6, 2022
When you scan the clothing tag, a 3D character appears and informs you of the clothing information.

1. Introduction When you scan the clothing tag, a 3D character appears and tells you the information on the clothes. You can select necessary informat

kimniki 0 Dec 23, 2021
3D Touch Application for Weighing Plums (and other small fruit!)

Plum-O-Meter ###3D Touch Application for Weighing Plums (and other small fruit!) Companion project to this blog post: http://flexmonkey.blogspot.co.uk

simon gladman 526 Sep 27, 2022
The code for my CoreGraphics+CoreAnimation talk, held during the 2012 iOS Game Design Seminar at the Technical University Munich.

PKCoreTechniques ======= Core Techniques is the result of a presentation I held at the Technical University of Munich during the 'iOS Game Design Semi

Philip Kluz 143 Sep 21, 2022
Visual designing library for iOS & OSX

ProcessingKit ProcessingKit is a Visual designing library for iOS & OSX. ProcessingKit written in Swift ?? and you can write like processing. Demo Dem

Atsuya Sato 333 Nov 12, 2022
🌈 Highly customizable Core Graphics based gradient view for iOS

MKGradientView Highly customizable Core Graphics based gradient view Features Available gradient types: Linear (Axial) Radial (Circular) Conical (Angu

Max Konovalov 167 Dec 27, 2022
GraphLayout - iOS UI controls to visualize graphs. Powered by Graphviz

GraphLayout GraphLayout - UI controls for graph visualization. It is powered by Graphviz. Graph visualization is a way of representing structural info

null 97 Sep 26, 2022
🎞 Powerful gradient animations made simple for iOS.

AnimatedGradientView is a UIView subclass which makes it simple to add animated gradients to your iOS app. It is written purely in Swift. Further docu

Ross Butler 431 Dec 12, 2022