NAME
Data::Sofu::SofuML - Interface to various binary drivers
DESCRIPTION
This Module is used to convert Sofu Trees to XML Tree.
This is mostly for convertig Sofu data via XSLT or similar.
You don't need to use this module directly.
Synopsis
use Data::Sofu;
my $sofu = readSofu("file.sofu");
writeSofuML("file.xml",$sofu,getSofucomments());
#And back
my $xml = readSofu("file.xml"); #readSofu can detect SofuML files.
writeSofu("file.sofu",$xml,getSofucomments());
Using the Sofu OO syntax:
require Data::Sofu;
my $s = Data::Sofu::new();
my $sofu = $s->read("file.sofu");
$s->writeML("file.xml",$sofu,$s->comments());
#And back
my $xml = $s->read("file.xml"); #read also detects SofuML files.
$s->write("file.sofu",$xml,$s->comments());
Using scalars instead of files:
require Data::Sofu;
my $s = Data::Sofu::new();
my $sofu = $s->read("file.sofu");
my $xmlstring = $s->packML($sofu,$s->comments()); #Contains now the xml files content
my $xml = $s->unpack($xmlstring);
$s->write($xml,$s->comments());
But: $scalar=packML() is not the same as writeML(\$scalar), packML will not indent the file.
SYNTAX
This Module is pure OO, exports nothing
METHODS
Most of these Methods (except pack()) are ony for internal use.
new()
Creates a new Data::Sofu::SofuML
and returns it.
XMLescape(STRING,LEVEL)
Returns the (quite badly) escaped form of STRING
XMLKeyescape(KEY)
Returns the (quite badly) escaped form of KEY
genID()
Returns a new unqiue ID
indent(LEVEL)
Returns the indentation for LEVEL
packObjectComment(OBJECT)
Returns the packed comment of OBJECT
packComment(TREE)
Returns the packed comment of the object reference by TREE
packElement(ELEMENT,OBJECT,LEVEL,ID)
Returns the ELEMENT for OBJECT
packItem(ELEMENT,LEVEL,ID,TREE)
Returns the an XML item
packObjectData(OBJECT,LEVEL)
Converts one Data::Sofu::Object into its XML representation
packData(DATA,LEVEL,TREE)
Converts one perl structure into its XML representation
packObject(OBJECT,[HEADER])
Converts one Data::Sofu::Object into its XML representation
pack(TREE,[COMMENTS,[HEADER]])
packs TREE to XML using Comments
- TREE
-
Perl datastructure to pack. Can be a hash, array or scalar (or array of hashes of hashes of arrays or whatever). Anything NOT a hash will be converted to TREE={Value=>TREE};
It can also be a Data::Sofu::Object or derived (Data::Sofu::Map, Data::Sofu::List, Data::Sofu::Value, Data::Sofu::...). Anything not a Data::Sofu::Map will be converted to one (A Map with one attribute called "Value" that holds TREE).
- COMMENTS
-
Comment hash (as returned by Data::Sofu::getSofucomments() or Data::Sofu->new()->comments() after any file was read).
These are ignored if TREE is a Data::Sofu::Object or derived. Data::Sofu::Object's store their comments in themselves. See Data::Sofu::Object->importComments() to import them.
Can be undef or {}.
load (STRING)
Unpacks a SofuML string to perl datastructures
Don't use this, use readSofu("file.xml") instead.
load (STRING)
Unpacks SofuML string to Data::Sofu::Object's from STRING
Don't use this, use readSofu("file.xml") instead.
BUGS
Reading SofuML files need XML::Parser.