$ show antchfx/xmlquery
xmlquery is a Go library for querying XML documents using XPath expressions. It provides functions to parse XML from various sources (string, file, URL, etc.), execute XPath queries, and manipulate the resulting node tree. The library features a caching mechanism for compiled XPath expressions to improve query performance and supports streaming parsing for large XML files to minimize memory usage. The architecture is modular, with separate concerns for parsing, querying, and node manipulation, and it relies on external dependencies for XPath expression handling and LRU caching.
The LLM identified 2 files worth highlighting for reuse:
Implements a buffered reader that can optionally cache data read from an underlying source. This utility is useful in parsing scenarios requiring lookahead or capture of specific sections (e.g., CDATA). It is self-contained, depending only on the standard library, and can be extracted into any project needing similar functionality.
Provides a thread-safe LRU cache for expensive computations (like compiling XPath expressions) with lazy initialization. The cache uses a mutex for concurrent access and sync.Once to ensure the cache is created only once. This pattern is reusable for any caching scenario where the cost of creating the cached value is high.