A simple XML parsing library for Swift that wraps XMLParser with a SwiftyJSON-like API.
SWXMLHash is a Swift library that simplifies XML parsing by wrapping Apple's XMLParser with a more intuitive, SwiftyJSON-like API. It allows developers to access XML elements and attributes using subscript notation, supports lazy parsing for large documents, and enables deserialization into custom Swift types. It solves the problem of verbose and complex XML handling in Swift applications.
Swift developers working on iOS, macOS, tvOS, or watchOS applications that need to parse or interact with XML data, such as those consuming web services, RSS feeds, or configuration files.
Developers choose SWXMLHash because it dramatically reduces the boilerplate and complexity associated with XMLParser, offering a familiar dictionary-like interface, robust deserialization capabilities, and performance optimizations like lazy parsing, all within a pure Swift implementation.
Simple XML parsing in Swift
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Provides a clean, SwiftyJSON-like syntax for accessing XML elements and attributes, making code more readable and less verbose than direct XMLParser usage, as highlighted in the README's examples.
Supports lazy loading of large XML documents through configuration, improving memory efficiency and performance for big files, with config.shouldProcessLazily enabling this feature.
Allows conversion of XML nodes into custom Swift types using XMLObjectDeserialization, with built-in support for common types and extensibility for custom converters, demonstrated in the deserialization examples.
Offers configurable options like case-insensitive lookups, namespace processing, and character encoding, providing adaptability to various XML formats without modifying core logic.
The library is parsing-only and does not provide functionality to generate or write XML, as stated in the FAQ, requiring separate solutions for output needs.
Error handling does not work with lazy loaded XML because parsing occurs only when elements are accessed, making it harder to detect issues early, as warned in the README's error handling section.
Can encounter EXC_BAD_ACCESS errors when parsing XML with byte order marks, requiring manual stripping of BOM characters beforehand, as noted in the FAQ troubleshooting.
Implementing custom deserialization for types like enums or classes requires additional protocol conformance and can be verbose, with examples in the FAQ showing extra steps for NSDate or enum handling.