Latest 1.2.1
Homepage https://github.com/PauliusVindzigelskis/GlimpseXML
License MIT
Platforms osx 10.13, ios 8.0
Authors

Version
Build Status

Fast DOM parser & serializer in pure Swift for iOS & Mac

Parsing & XPath Example

import GlimpseXML

let music = "~/Music/iTunes/iTunes Music Library.xml".stringByExpandingTildeInPath
let doc = try GlimpseXML.Document.parseFile(music)
let rootNodeName: String? = doc.rootElement.name
println("Library Type: (rootNodeName)")

let trackCount = doc.xpath("/plist/dict/key[text()='Tracks']/following-sibling::dict/key").value?.first?.text
println("Track Count: (trackCount)")

let dq = doc.xpath("//key[text()='Artist']/following-sibling::string[text()='Bob Dylan']").value?.count
println("Dylan Quotient: (dq)")

Generating & Serializing Example

You can manually create an XML DOM using Glimpse.XML Node elements. Convenience constructors are provided
in order to make tree construction naturally fit the hierarchy of an XML document.

import GlimpseXML

let node = Node(name: "library", attributes: [("url", "glimpse.io")], children: [
    Node(name: "inventory", children: [
        Node(name: "book", attributes: [("checkout", "true")], children: [
            Node(name: "title", text: "I am a Bunny" ),
            Node(name: "author", text: "Richard Scarry"),
            ]),
        Node(name: "book", attributes: [("checkout", "false")], children: [
            Node(name: "title", text: "You were a Bunny" ),
            Node(name: "author", text: "Scarry Richard"),
            ]),
        ]),
    ])

You can also serialize the node to a String:

let compact: String = node.serialize()
println(compact)

Yielding:

<library url="glimpse.io"><inventory><book checkout="true"><title>I am a Bunny</title><author>Richard Scarry</author></book><book checkout="false"><title>You were a Bunny</title><author>Scarry Richard</author></book></inventory></library>

With formatting:

let formatted: String = node.serialize(indent: true)
println(formatted)
<library url="glimpse.io">
  <inventory>
    <book checkout="true">
      <title>I am a Bunny</title>
      <author>Richard Scarry</author>
    </book>
    <book checkout="false">
      <title>You were a Bunny</title>
      <author>Scarry Richard</author>
    </book>
  </inventory>
</library>

You can also include a doc header with an encoding by wrapping the Node in a Document:

let doc = Document(root: node)
let encoded: String = doc.serialize(indent: true, encoding: "ISO-8859-1")
println(encoded)

Which will output:

<?xml version="1.0" encoding="ISO-8859-1"?>
<library url="glimpse.io">
  <inventory>
    <book checkout="true">
      <title>I am a Bunny</title>
      <author>Richard Scarry</author>
    </book>
    <book checkout="false">
      <title>You were a Bunny</title>
      <author>Scarry Richard</author>
    </book>
  </inventory>
</library>

Setting up GlimpseXML

Cocoapod

pod 'GlimpseXML'

Manual

GlimpseXML is a single cross-platform iOS & Mac Framework. To set it up in your project, simply add it as a github submodule, drag the GlimpseXML.xcodeproj into your own project file, add GlimpseXML.framework to your target’s dependencies, and import GlimpseXML from any Swift file that should use it.

Set up Git submodule

  1. Open a Terminal window
  2. Change to your projects directory cd /path/to/MyProject
  3. If this is a new project, initialize Git: git init
  4. Add the submodule: git submodule add https://github.com/glimpseio/GlimpseXML.git GlimpseXML.

Set up Xcode

  1. Find the GlimpseXML.xcodeproj file inside of the cloned GlimpseXML project directory.
  2. Drag & Drop it into the Project Navigator (⌘+1).
  3. Select your project in the Project Navigator (⌘+1).
  4. Select your target.
  5. Select the tab Build Phases.
  6. Expand Link Binary With Libraries.
  7. Add GlimpseXML.framework
  8. Add import GlimpseXML to the top of your Swift source files.

Latest podspec

{
    "name": "GlimpseXML",
    "version": "1.2.1",
    "swift_version": "5.0",
    "summary": "Fast DOM parser & serializer",
    "description": "Fast DOM parser & serializer in pure Swift for iOS & Mac",
    "homepage": "https://github.com/PauliusVindzigelskis/GlimpseXML",
    "license": {
        "type": "MIT",
        "file": "LICENSE.md"
    },
    "authors": {
        "Paulius Vindzigelskis": "[email protected]"
    },
    "source": {
        "git": "https://github.com/PauliusVindzigelskis/GlimpseXML.git",
        "tag": "1.2.1"
    },
    "platforms": {
        "osx": "10.13",
        "ios": "8.0"
    },
    "preserve_paths": "Modules/*",
    "source_files": "GlimpseXML/*.{swift}",
    "libraries": "xml2",
    "xcconfig": {
        "HEADER_SEARCH_PATHS": "$(SDKROOT)/usr/include/libxml2"
    }
}

Pin It on Pinterest

Share This