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
Learn to parse XML and HTML documents, walk element trees, and query with XPath using SwiftLibXML.
Essentials
Add SwiftLibXML to a package and parse your first XML document.
Set up a document, read the root element, and walk the tree.
Select matching elements with XPath expressions.
Query namespace-prefixed elements and attributes using XPath.
Notes about the lower-level wrappers that back the public API.
Parsing Documents
A Swift wrapper around a libxml2 document.
In-memory XML parser.
In-memory HTML parser.
Traversing Trees
A Swift wrapper around a libxml2 element node.
Enumerates a document tree while preserving node depth and parentage.
A Swift wrapper around a libxml2 attribute node.
A Swift wrapper around a libxml2 namespace definition.
Querying
A collection wrapper around a libxml2 XPath result.
Supporting Helpers
Returns an iterator that never yields a value.
Returns an empty sequence for the requested element type.