The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

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.

whiteescape (STRING)

Escapes whitespace for use in XML

XMLescapeOld(STRING,LEVEL)

Older version of XMLescape, still need by some.

XMLescape(STRING,LEVEL)

Returns the (quite badly) escaped form of STRING

XMLunescape(STRING)

Inversion of XMLescape

XMLunescapeRestrictive(STRING)

Like XMLunescape, but more restrictive (currently not used)

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

packElement2(ELEMENT,OBJECT,LEVEL,ID)

Same as packElement, without comments.

packItem(ELEMENT,LEVEL,ID,TREE)

Returns the the XML version of an item

packItem2(ELEMENT,LEVEL,ID,TREE)

Same as packItem, but doesn't write a comment.

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 {}.

read(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.

tag_start

Handler for XML::Parser

characters

Handler for XML::Parser

comment

Handler for XML::Parser

tag_end

Handler for XML::Parser

otag_start

Handler for XML::Parser, object mode

ocharacters

Handler for XML::Parser, object mode

ocomment

Handler for XML::Parser, object mode

otag_end

Handler for XML::Parser, object mode

BUGS

Reading SofuML files need XML::Parser.

The Old escaping mechanism didn't escape newlines in Values (at least not the ones in the middle)

The new mechanism escapes them all.

This Module can read both, but if you encounter NewLines in your Source file that don't belong there it might give you an additional newline you didn't want.

See Also

Data::Sofu, Data::Sofu::Object, http://sofu.sf.net