晋太元中,武陵人捕鱼为业。缘溪行,忘路之远近。忽逢桃花林,夹岸数百步,中无杂树,芳草鲜美,落英缤纷。渔人甚异之,复前行,欲穷其林。 林尽水源,便得一山,山有小口,仿佛若有光。便舍船,从口入。初极狭,才通人。复行数十步,豁然开朗。土地平旷,屋舍俨然,有良田、美池、桑竹之属。阡陌交通,鸡犬相闻。其中往来种作,男女衣着,悉如外人。黄发垂髫,并怡然自乐。 见渔人,乃大惊,问所从来。具答之。便要还家,设酒杀鸡作食。村中闻有此人,咸来问讯。自云先世避秦时乱,率妻子邑人来此绝境,不复出焉,遂与外人间隔。问今是何世,乃不知有汉,无论魏晋。此人一一为具言所闻,皆叹惋。余人各复延至其家,皆出酒食。停数日,辞去。此中人语云:“不足为外人道也。”(间隔 一作:隔绝) 既出,得其船,便扶向路,处处志之。及郡下,诣太守,说如此。太守即遣人随其往,寻向所志,遂迷,不复得路。 南阳刘子骥,高尚士也,闻之,欣然规往。未果,寻病终。后遂无问津者。
|
Server : Apache System : Linux srv.rainic.com 4.18.0-553.47.1.el8_10.x86_64 #1 SMP Wed Apr 2 05:45:37 EDT 2025 x86_64 User : rainic ( 1014) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /usr/share/doc/libxmlb/ |
Upload File : |
libxmlb
=======
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 -- its 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.
| Example | Description | Supported |
| --- | --- | --- |
| `/bookstore` | Returns the root bookstore element | ✔ |
| `/bookstore/book` | Returns all `book` elements | ✔ |
| `//book` | Returns books no matter where they are | ✖ |
| `bookstore//book` | Returns books that are descendant of `bookstore` | ✖ |
| `@lang` | Returns 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::bookstore` | Returns 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.
| Example | Description | Supported |
| --- | --- | --- |
| `/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 `lang`equal `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]/title` | Returns 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.