A Go package for querying XML documents using XPath expressions with built-in caching for performance.
xmlquery is a Go package that allows developers to query XML documents using XPath expressions. It provides functions to parse XML from various sources, extract specific nodes or data, and evaluate XPath expressions efficiently. The package solves the problem of navigating and extracting information from complex XML structures in Go applications.
Go developers who need to parse, query, or process XML data in their applications, such as those working with web scraping, data feeds, configuration files, or API responses in XML format.
Developers choose xmlquery for its built-in query caching, which improves performance by avoiding XPath recompilation, and its support for streaming parsing of large XML files, making it memory-efficient. It also offers comprehensive XPath 1.0/2.0 support and easy integration with Go's standard library.
xmlquery is Golang XPath package for XML query.
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Supports XPath 1.0/2.0 expressions for complex queries, enabling filtering, counting, and extraction, as shown in examples like //book[price<5] or sum(//book/price).
Built-in query caching avoids recompilation of XPath expressions, improving performance for repeated queries, mentioned in the overview and FAQ.
CreateStreamParser allows parsing large XML files without loading the entire document into memory, ideal for big data sets, with examples for simple and advanced filtering.
Can parse XML from strings, files, URLs, or any io.Reader, providing versatility in data sources, as demonstrated in quick start code snippets.
For basic XML parsing, the standard Go encoding/xml package is simpler; xmlquery's XPath focus adds overhead and a steeper learning curve for straightforward tasks.
CreateStreamParser has restrictions, such as handling only simple cases without advanced filtering, as noted in the README, which may not suit all streaming needs.
Querying namespaced XML requires explicit prefix mapping with CompileWithNS, which can be error-prone and cumbersome compared to automatic namespace handling.
Find() panics on invalid XPath, while QueryAll() returns an error, leading to potential confusion and less graceful error management in applications.