Documentation Language: Swift

Framework

SwiftLibXML

Parse and query XML and HTML documents with a small Swift wrapper around libxml2.

Overview

SwiftLibXML wraps libxml2 document, element, attribute, namespace, and XPath handles in Swift types that are easy to traverse and compare. The package keeps libxml2 close to the surface, while still offering Swift-friendly iteration and lookup APIs.

Use XMLDocument to parse data or a file, read the rootElement, and then walk the tree with XMLElement and XMLTree. Namespace-aware XPath queries are available through xpath(_:namespaces:defaultPrefix:) and xpath(_:namespaces:).

Topics

Tutorials

Co
SwiftLibXML Tutorials

Learn to parse XML and HTML documents, walk element trees, and query with XPath using SwiftLibXML.

Essentials

A
Getting Started with SwiftLibXML

Add SwiftLibXML to a package and parse your first XML document.

A
Parsing and Traversal

Set up a document, read the root element, and walk the tree.

A
XPath Queries

Select matching elements with XPath expressions.

A
Working with Namespaces

Query namespace-prefixed elements and attributes using XPath.

A
Implementation Notes

Notes about the lower-level wrappers that back the public API.

Parsing Documents

C
XMLDocument

A Swift wrapper around a libxml2 document.

V
xmlMemoryParser

In-memory XML parser.

V
htmlMemoryParser

In-memory HTML parser.

Traversing Trees

S
XMLElement

A Swift wrapper around a libxml2 element node.

S
XMLTree

Enumerates a document tree while preserving node depth and parentage.

S
XMLAttribute

A Swift wrapper around a libxml2 attribute node.

S
XMLNameSpace

A Swift wrapper around a libxml2 namespace definition.

Querying

S
XMLPath

A collection wrapper around a libxml2 XPath result.

Supporting Helpers

F
emptyIterator()

Returns an iterator that never yields a value.

F
emptySequence()

Returns an empty sequence for the requested element type.