descriptionnone
repository URLhttps://github.com/hughsie/libxmlb.git
owner7CuqrB6UpLdECD4m@atomicmail.io
last changeMon, 27 Oct 2025 10:50:52 +0000 (27 10:50 +0000)
last refreshSun, 2 Nov 2025 07:27:22 +0000 (2 08:27 +0100)
content tags
README.md

libxmlb

Coverity Scan Build Status OpenSSF Scorecard

Introduction

XML is slow to parse and strings inside the document cannot be memory mapped as they do not have a trailing NUL char. The libxmlb library takes XML source, and converts it to a structured binary representation with a deduplicated string table -- where the strings have the NULs included.

This allows an application to mmap the binary XML file, do an XPath query and return some strings without actually parsing the entire document. This is all done using (almost) zero allocations and no actual copying of the binary data.

As each node in the binary XML file encodes the 'next' node at the same level it makes skipping whole subtrees trivial. A 10Mb binary XML file can be loaded from disk and queried in less than a few milliseconds.

The binary XML is not supposed to be small. It's usually about half the size of the text XML data where a lot of the tag content is duplicated, but can actually be larger than the original XML file. This isn't important; the fast query speed and the ability to mmap strings without copies more than makes up for the larger on-disk size. If you want to compress your XML, this library probably isn't for you -- just use gzip -- it gives you an almost a perfect compression ratio for data like this.

For example:

$ xb-tool compile fedora.xmlb fedora.xml.gz

$ du -h fedora.xml*
12M         fedora.xmlb
3.6M        fedora.xml.gz

$ xb-tool query fedora.xmlb "components/component[@type=desktop]/id[text()=firefox.desktop]"
RESULT: firefox.desktop
real        0m0.011s
user        0m0.010s
sys         0m0.001s

XPath

This library only implements a tiny subset of XPath. See the examples for the full list, but it's basically restricted to element_name, attributes and text.

We will use the following XML document in the examples below.

<?xml version="1.0" encoding="UTF-8"?>
<bookstore>
  <book>
    <title lang="en">Harry Potter</title>
    <price>29.99</price>
  </book>
  <book percentage="99">
    <title lang="en">Learning XML</title>
    <price>39.95</price>
  </book>
</bookstore>

Selecting Nodes

XPath uses path expressions to select nodes in an XML document. The only thing that libxmlb can return are nodes.

ExampleDescriptionSupported
/bookstoreReturns the root bookstore element
/bookstore/bookReturns all book elements
//bookReturns books no matter where they are
bookstore//bookReturns books that are descendant of bookstore
@langReturns attributes that are named lang
/bookstore/.Returns the bookstore node
/bookstore/book/*Returns all title and price nodes of each book node
/bookstore/book/child::*Returns all title and price nodes of each book node
/bookstore/book/title/..Returns the book nodes with a title
/bookstore/book/parent::*Returns bookstore, the parent of book
/bookstore/book/parent::bookstoreReturns the parent bookstore of book

Predicates

Predicates are used to find a specific node or a node that contains a specific value. Predicates are always embedded in square brackets.

ExampleDescriptionSupported
/bookstore/book[1]Returns the first book element
/bookstore/book[first()]Returns the first book element
/bookstore/book[last()]Returns the last book element
/bookstore/book[last()-1]Returns the last but one book element
/bookstore/book[position()<3]Returns the first two books
/bookstore/book[upper-case(text())=='HARRY POTTER']Returns the first book
/bookstore/book[@percentage>=90]Returns the book with >= 90% completion
/bookstore/book/title[@lang]Returns titles with an attribute named lang
/bookstore/book/title[@lang='en']Returns titles that have a langequal en
/bookstore/book/title[@lang!='en']Returns titles that have a lang not equal en
/bookstore/book/title[@lang<='zz_ZZ']Returns titles that lang <= zz_ZZ
/bookstore/book[price>35.00]Returns the books with a price greater than 35
/bookstore/book[price>35.00]/titleReturns the titles that have a price greater than 35
/bookstore/book/title[text()='Learning XML']Returns the book node with matching content

Compilation

libxmlb is a standard meson project. It can be compiled using the following basic steps:

# meson build
# ninja -C build
# ninja -C build install
# ldconfig

This will by default install the library into /usr/local. On some Linux distributions you may need to configure the linker path in /etc/ld.so.conf to be able to locate it. The call to ldconfig is needed to refresh the linker cache.

meson build has options that can be used to disable certain features, e.g.

# meson build -Dintrospection=false -Dgtkdoc=false -Dcli=false

will remove support for GObject introspection, Gtk documentation, and will only build the library without the command line tool. As a result, fewer libraries are needed for building and running the project.

shortlog
5 days ago dependabot... build(deps): bump actions/upload-artifact from 4.6... main
5 days ago dependabot... build(deps): bump github/codeql-action from 4.30.9...
12 days ago dependabot... build(deps): bump github/codeql-action from 4.30.8...
2025-10-13 dependabot... build(deps): bump github/codeql-action from 3.30.6...
2025-10-06 dependabot... build(deps): bump ossf/scorecard-action from 2.4.2...
2025-10-06 dependabot... build(deps): bump github/codeql-action from 3.30.5...
2025-09-29 dependabot... build(deps): bump github/codeql-action from 3.30.3...
2025-09-15 dependabot... build(deps): bump github/codeql-action from 3.30.1...
2025-09-10 Richard Hughestrivial: post release version bump
2025-09-10 Richard HughesRelease libxmlb 0.3.240.3.24
2025-09-08 Richard HughesRevert "Add xb_node_get_attrs() for fwupd"
2025-09-08 Richard HughesRevert "Add xb_builder_node_set_attrs() for fwupd"
2025-09-08 dependabot... build(deps): bump github/codeql-action from 3.29.11...
2025-09-05 Richard HughesDo not reverse the order of attrs when using xb_node_at...
2025-09-05 Richard HughesAdd xb_builder_node_set_attrs() for fwupd
2025-09-05 Richard HughesAdd xb_node_get_attrs() for fwupd
...
tags
7 weeks ago 0.3.24 Release libxmlb 0.3.24
2 months ago 0.3.23 Release libxmlb 0.3.23
7 months ago 0.3.22 Release libxmlb 0.3.22
12 months ago 0.3.21 Release libxmlb 0.3.21
12 months ago 0.3.20 Release libxmlb 0.3.20
18 months ago 0.3.19 Release libxmlb 0.3.19
18 months ago 0.3.18 Release libxmlb 0.3.18
18 months ago 0.3.17 Release libxmlb 0.3.17
18 months ago 0.3.16 Release libxmlb 0.3.16
22 months ago 0.3.15 Release libxmlb 0.3.15
2 years ago 0.3.14 Release libxmlb 0.3.14
2 years ago 0.3.13 Release libxmlb 0.3.13
2 years ago 0.3.12 Release libxmlb 0.3.12
2 years ago 0.3.11 Release libxmlb 0.3.11
3 years ago 0.3.10 Release libxmlb 0.3.10
3 years ago 0.3.9 Release libxmlb 0.3.9
...
heads
5 days ago main
6 months ago hughsie/XbBuilder-final
3 years ago wip/hughsie/xb_builder_add_default_locales
5 years ago 0_1_X