this class can be used in two modes:
1. create an XML document from an array or object that is processed by other
applications. That means, you can create a RDF document from an array in the
following format:
$data = array(
"channel" => array(
"title" => "Example RDF channel",
"link" => "http://www.php-tools.de",
"image" => array(
"title" => "Example image",
"url" => "http://www.php-tools.de/image.gif",
"link" => "http://www.php-tools.de"
),
array(
"title" => "Example item",
"link" => "http://example.com"
),
array(
"title" => "Another Example item",
"link" => "http://example.org"
)
)
);
to create a RDF document from this array do the following:
require_once 'XML/Serializer.php';
$options = array(
"indent" => "\t", // indent with tabs
"linebreak" => "\n", // use UNIX line breaks
"rootName" => "rdf:RDF", // root tag
"defaultTagName" => "item" // tag for values with numeric keys
);
$serializer = new XML_Serializer($options);
$rdf = $serializer->serialize($data);
You will get a complete XML document that can be processed like any RDF document.
2. this classes can be used to serialize any data structure in a way that it can
later be unserialized again.
XML_Serializer will store the type of the value and additional meta information
in attributes of the surrounding tag. This meat information can later be used
to restore the original data structure in PHP. If you want XML_Serializer
to add meta information to the tags, add
"typeHints" => true
to the options array in the constructor.
Future versions of this package will include an XML_Unserializer, that does
the unserialization automatically for you.