Elektra  0.8.24
Plugin: xerces

This plugin is a storage plugin allowing Elektra to read and write XML formatted files. It uses a general format which:

Usage

To mount an XML file we use:

    kdb mount file.xml user/test/file xerces

The strength and usage of this plugin is that it supports arbitrary XML files and does not require a specific format. Given the following example of an XML file:

    <?xml version="1.0" encoding="UTF-8" standalone="no" ?>
    <xerces>foo
      <bar meta="da_ta">bar</bar>
    </xerces>

Please note that if the key name does not correspond to the root element of the xml file, the original name gets stored in a metakey called xerces/rootname. The content of the root element gets mapped to the mountpoint.

We can observe the following result after mounting:

    kdb get user/test/file > foo
    kdb get user/test/file/bar > bar
    kdb getmeta user/test/file/bar meta > da_ta

To export an existing keyset to the XML format:

    kdb export user/test/xerces xerces > example.xml

The root element of the resulting XML file will be "xerces" again, restored via the metadata. If you don't want this behavior, delete the metadata xerces/rootname on the mountpoint, then it uses the mountpoint's name instead.

Dependencies

Limitations

This plugin is not able to handle key names which contain characters that are not allowed to appear as an XML element name. Consider using the rename plugin to take care about proper escaping.

The main rules of an XML element name are:

The root key is not allowed to be an array, as this would correspond to multiple root elements in XML (see the GitHub issue).

XSD transformations, schemas or DTDs are not supported yet.

Examples

Mounting, setting a key and exporting

# Backup-and-Restore:user/tests/xercesfile
sudo kdb mount xerces.xml user/tests/xercesfile xerces
kdb set user/tests/xercesfile foo
kdb setmeta user/tests/xercesfile xerces/rootname xerces
kdb set user/tests/xercesfile/bar bar
kdb setmeta user/tests/xercesfile/bar meta "da_ta"
kdb getmeta user/tests/xercesfile xerces/rootname
#> xerces
kdb get user/tests/xercesfile/bar
#> bar
kdb export user/tests/xercesfile xerces
# STDOUT-REGEX: <bar meta="da_ta">bar</bar>
sudo kdb rm -r user/tests/xercesfile
sudo kdb umount user/tests/xercesfile