table of contents
| md_src_plugins_xerces_README(3elektra) | Elektra | md_src_plugins_xerces_README(3elektra) |
NAME¶
md_src_plugins_xerces_README - Plugin: xerces
- infos = Information about the xerces plugin is in keys below
- infos/author = Armin Wurzinger e1528532@libelektra.org
- infos/licence = BSD
- infos/provides = storage/xml
- infos/needs =
- infos/placements = getstorage setstorage
- infos/status = recommended unittest experimental
- infos/metadata = xerces/rootname
- infos/description = Storage in the XML format.
This plugin is a storage plugin allowing Elektra to read and write XML formatted files. It uses a general format which:
- Maps key names to XML elements
- Maps key values to textual content of XML elements
- Maps metakeys to XML attributes. Metakey name = attribute name, Metakey value = attribute value
- Ignores XML comments
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¶
- Xerces-C++ 3.0.0 or newer (apt-get install libxerces-c-dev)
- CMake 3.6 or a copy of FindXercesC.cmake in /usr/share/cmake-3.0/Modules/
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:
- Element names must start with a letter or underscore
- Element names cannot start with the letters xml (or XML, or Xml, etc.)
- Element names can contain letters, digits, hyphens, underscores, and periods
- Element names cannot contain spaces
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:/examples/xercesfile sudo kdb mount xerces.xml /examples/xercesfile xerces kdb set /examples/xercesfile foo kdb setmeta /examples/xercesfile xerces/rootname xerces kdb set /examples/xercesfile/bar bar kdb setmeta /examples/xercesfile/bar meta "da_ta" kdb getmeta /examples/xercesfile xerces/rootname #> xerces kdb get /examples/xercesfile/bar #> bar kdb export /examples/xercesfile xerces #> <?xml version="1.0" encoding="UTF-8" standalone="no" ?> #> <xerces> #> #> <bar meta="da_ta">bar</bar>foo #> #> </xerces> sudo kdb rm -r /examples/xercesfile sudo kdb umount /examples/xercesfile
| Mon Jan 15 2018 | Version 0.8.20 |