Latest 2.2.0
Homepage https://github.com/onmyway133/Reindeers
License MIT
Platforms ios 8.0, osx 10.11, tvos 10.0, requires ARC
Authors

Version
Carthage Compatible
License
Platform
Swift

Reindeers

Description

Usage

XML, SVG, RSS

<html>
<body>

<h1>My first SVG</h1>

<svg width="100" height="100">
  <circle cx="50" cy="50" r="40" stroke="green" stroke-width="4" fill="yellow" />
</svg>

</body>
</html
let data = doItYourselfToLoadXMLStringFrom(fileName: "test4", ext: "svg")
let document = try! Document(data: data)

document.rootElement.name
document.rootElement.children()

document.rootElement.elements(XPath: "//svg").first?.attributes["width"]
document.rootElement.elements(XPath: "//circle").first?.attributes["stroke"]

HTML

<!DOCTYPE html>
<html>
  <head>
    <style>
      h1 {
        color: blue;
        font-family: verdana;
        font-size: 300%;

      }
    p  {
      color: red;
      font-family: courier;
      font-size: 160%;
    }
    </style>
  </head>
  <body>

    <h1>This is a heading</h1>
    <p>This is a paragraph.</p>
    <a href="http://www.w3schools.com">Visit W3Schools</a>

  </body>
</html>
let data = Utils.load(fileName: "test3", ext: "html")
let document = try? Document(data: data, kind: .html)

let body = document.rootElement.child(index: 1)
body?.elements(XPath: "//p").first?.content

Query

  • Get element info
let element = document.rootElement.child(index: 0)

element.name
element.ns
element.line
element.attributes
element.parent
element.nextSibling
element.previousSibling
  • Get child elements
element.children { child, index in
  return child.name == "a"
}

element.children(name: "item")
element.children(indexes: [0, 2, 4])
  • XPath
let body = document.rootElement.firstChild(name: "body")
body?.elements(XPath: "//a").first?.attributes["href"]
body?.elements(XPath: "//div") { element in
  return element.attributes["width"] == "100"
}
  • Turn Element to String
element.toAttributeString()
element.toXMLString()

Installation

Reindeers is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod 'Reindeers'

Reindeers is also available through Carthage.
To install just write into your Cartfile:

github "onmyway133/Reindeers"

Reindeers can also be installed manually. Just download and drop Sources folders in your project.

Author

Khoa Pham, [email protected]

Contributing

We would love you to contribute to Reindeers, check the CONTRIBUTING file for more info.

License

Reindeers is available under the MIT license. See the LICENSE file for more info.

Latest podspec

{
    "name": "Reindeers",
    "summary": "XML in Swift",
    "version": "2.2.0",
    "homepage": "https://github.com/onmyway133/Reindeers",
    "license": "MIT",
    "authors": {
        "Khoa Pham": "[email protected]"
    },
    "source": {
        "git": "https://github.com/onmyway133/Reindeers.git",
        "tag": "2.2.0"
    },
    "social_media_url": "https://twitter.com/onmyway133",
    "platforms": {
        "ios": "8.0",
        "osx": "10.11",
        "tvos": "10.0"
    },
    "requires_arc": true,
    "source_files": "Sources/**/*",
    "preserve_paths": "Cocoapods/*",
    "xcconfig": {
        "HEADER_SEARCH_PATHS": "$(SDKROOT)/usr/include/libxml2",
        "SWIFT_INCLUDE_PATHS": "$(SRCROOT)/Reindeers/Cocoapods"
    },
    "pod_target_xcconfig": {
        "SWIFT_VERSION": "4.2"
    }
}

Pin It on Pinterest

Share This