Pickler functions for converting between user defined data types
and XmlTree data. Usefull for persistent storage and retreival
of arbitray data as XML documents.
This module is an adaptation of the pickler combinators
developed by Andrew Kennedy
( https://www.microsoft.com/en-us/research/wp-content/uploads/2004/01/picklercombinators.pdf )
The difference to Kennedys approach is that the target is not
a list of Chars but a list of XmlTrees. The basic picklers will
convert data into XML text nodes. New are the picklers for
creating elements and attributes.
One extension was neccessary: The unpickling may fail.
Old: Therefore the unpickler has a Maybe result type.
Failure is used to unpickle optional elements
(Maybe data) and lists of arbitray length.
Since hxt-9.2.0: The unpicklers are implemented as
a parser monad with an Either err val result type.
This enables appropriate error messages , when unpickling
XML stuff, that is not generated with the picklers and which contains
some elements and/or attributes that are not handled when unpickling.
There is an example program demonstrating the use
of the picklers for a none trivial data structure.
(see "examples/arrows/pickle" directory in the hxt distribution)
Conversion of an XML document tree into an arbitrary data type
The inverse of pickleDoc.
This law should hold for all picklers: unpickle px . pickle px $ v == Just v .
Not every possible combination of picklers does make sense.
For reconverting a value from an XML tree, is becomes neccessary,
to introduce "enough" markup for unpickling the value
First apply a fixed pickler/unpickler, then a 2. one
If the first fails during unpickling, the whole pickler fails.
This can be used to check some properties of the input, e.g. whether
a given fixed attribute or a namespace declaration exists
(xpAddFixedAttr, xpAddNSDecl)
or to filter the input, e.g. to ignore some elements or attributes
(xpFilterCont, xpFilterAttr).
When pickling, this can be used to insert some fixed XML pieces,
e.g. namespace declarations,
class attributes or other stuff.
Run two picklers in sequence like with xpSeq.
If during unpickling the first one fails,
an alternative pickler (first argument) is applied.
This pickler is only used as combinator for unpickling.
One of the most often used primitive picklers. Attention:
For pickling empty strings use xpText0. If the text has a more
specific datatype than xsd:string, use xpTextDT
Text pickler with a description of the structure of the text
by a schema. A schema for a data type can be defined by scDT.
In Text.XML.HXT.Arrow.Pickle.Schema there are some more functions for creating
simple datatype descriptions.
Must be used in all places, where empty strings are legal values.
If the content of an element can be an empty string, this string disapears
during storing the DOM into a document and reparse the document.
So the empty text node becomes nothing, and the pickler must deliver an empty string,
if there is no text node in the document.
Pickle a string representing XML contents by inserting the tree representation into the XML document.
Unpickling is done by converting the contents with
xshowEscapeXml into a string,
this function will escape all XML special chars, such that pickling the value back becomes save.
Pickling is done with xread
Encoding of list values by pickling all list elements sequentially.
Unpickler relies on failure for detecting the end of the list.
The standard pickler for lists. Can also be used in combination with xpWrap
for constructing set and map picklers
This pickler converts a map into a list of pairs.
All key value pairs are mapped to an element with name (1.arg),
the key is encoded as an attribute named by the 2. argument,
the 3. arg is the pickler for the keys, the last one for the values
Every constructor is mapped to an index into the list of picklers.
The index is used only during pickling, not during unpickling, there the 1. match is taken
Pickler for wrapping/unwrapping data into an XML element with an attribute with given value
To make XML structures flexible but limit the number of different elements, it's sometimes
useful to use a kind of generic element with a key value structure
When generating XML the namespace decl is added,
when reading a document, the unpickler checks
whether there is a namespace declaration for the given
namespace URI (2. arg)