Repolode
beevik

beevik/etree

A lightweight pure-Go package that parses, queries, modifies and writes XML as an element tree, with XPath-like path queries.

Stars
1,672
Forks
191
Open issues
4
Last commit
last month

What is it?

etree represents XML documents as trees of elements, which makes it straightforward to traverse, search and change them in Go. It can build a document from scratch, or read one from a file, byte slice, string or io.Reader, and write it back out with optional indentation using spaces or tabs.

The package offers simple selection methods for child elements and attributes, along with lightweight XPath-like path queries. Paths can be compiled ahead of time for repeated searches, and they support recursive lookups with double slashes and predicates such as attribute or namespace-prefixed value matches. Its design was inspired by Python's ElementTree module.

etree is implemented in pure Go with only standard library dependencies, and is built on top of the standard encoding/xml package. It requires Go 1.23 or later.

Key features

  • 01Builds XML documents from scratch or parses them from files, strings, byte slices and io.Reader.
  • 02Searches with simple selectors or XPath-like path queries, including recursive and predicate-based lookups.
  • 03Pre-compiled paths allow efficient repeated queries.
  • 04Auto-indents serialized output with spaces or tabs.
  • 05Pure Go with no dependencies beyond the standard library.

Use cases

  • Reading and modifying XML configuration files in a Go service.
  • Generating XML documents such as feeds or structured exports from Go code.
  • Extracting specific values from large XML payloads using path queries.

Quick start

  1. 1

    Install the etree package with go get

    go get github.com/beevik/etree
  2. 2

    Create a new XML document and write it to stdout in your Go program, as shown in the README's creation example

Topics

#xml#go#xpath#xml-parser#dom#etree#path

FAQ

What is etree?
A lightweight pure-Go package that parses, queries, modifies and writes XML as an element tree, with XPath-like path queries. etree represents XML documents as trees of elements, which makes it straightforward to traverse, search and change them in Go. It can build a document from scratch, or read one from a file, byte slice, string or io.Reader, and write it back out with optional indentation using spaces or tabs.
Is etree free to use? What license does it have?
etree is open source under the BSD-2-Clause license. Check the license terms before using it in commercial products.
Is etree still maintained?
Updated within 6 months. The last commit to etree was on Sep 23, 2026.
What can I use etree for?
Reading and modifying XML configuration files in a Go service. Generating XML documents such as feeds or structured exports from Go code. Extracting specific values from large XML payloads using path queries.
How do I install etree?
Install the etree package with go get: go get github.com/beevik/etree Create a new XML document and write it to stdout in your Go program, as shown in the README's creation example
Where can I get etree?
The source code and installation instructions are on GitHub: https://github.com/beevik/etree

Summary generated by AI from the project's README. GitHub stats refresh daily.

Related projects

A Java library for parsing, scraping, editing and sanitizing real-world HTML using DOM methods, CSS selectors and XPath.

Backend & APIs#java#html-parser#web-scraping
11.4K2.3KJavaMITWell maintainedUpdated 3 days ago

Fast, jQuery-style library for parsing and manipulating HTML and XML documents on the server or in the browser.

Developer Tools#html-parser#jquery#scraping
30.5K1.7KTypeScriptMITWell maintainedUpdated yesterday