Latest 1.0.3
License MIT
Platforms osx 10.13, ios 8.0

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? =
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", "")], 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()


<library url=""><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)
<library url="">
    <book checkout="true">
      <title>I am a Bunny</title>
      <author>Richard Scarry</author>
    <book checkout="false">
      <title>You were a Bunny</title>
      <author>Scarry Richard</author>

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")

Which will output:

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

Setting up GlimpseXML

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 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.0.3",
    "swift_version": "3.0",
    "summary": "Fast DOM parser & serializer",
    "description": "Fast DOM parser & serializer in pure Swift for iOS & Mac",
    "homepage": "",
    "license": {
        "type": "MIT",
        "file": ""
    "authors": {
        "Paulius Vindzigelskis": "[email protected]"
    "source": {
        "git": "",
        "tag": "1.0.3"
    "platforms": {
        "osx": "10.13",
        "ios": "8.0"
    "preserve_paths": "Modules/*",
    "source_files": "GlimpseXML/*.{swift}",
    "libraries": "xml2",
    "xcconfig": {
        "HEADER_SEARCH_PATHS": "$(SDKROOT)/usr/include/libxml2",
        "SWIFT_INCLUDE_PATHS": "$(SRCROOT)/GlimpseXML/Modules"

Pin It on Pinterest

Share This