Pitonyak::XMLUtil - Convert Objects to and from XML.


A few simple XML utilities that will convert arbitrary objects to XML and back again. These routines have not been extensively tested.



Change '&amp;' to '&', '&lt;' to '<', '&gt;' to '>', '&quot;' to '``', and '&apos;' to '''``.

The calling parameters are modfied



Change '&' to '&amp;', '<' to '&lt;', '>' to '&gt;', '``' to '&quot;', and '''`` to '&apos;',

The calling parameters are modfied.

This is used to render a string safe to send as XML. Existing entity referenes will have their leading ampersand transformed.



Transform an object into XML. An attempt is made to make this object human readable. Note that if the object is a package object that is referenced as a HASH it is still embedded as a HASH.

Each object in the array is returned as a separate XML string.

An object that is not defined is returned as <NULL/>>

A SCALAR is rendered XML safe by converting special characters to entity references. It is otherwise left unchanged.

A Reference to a SCALAR is encoded as <REF/> for a zero length SCALAR and as <REF>value</REF>

An ARRAY reference is encoded as either <ARRAY/> or something similar to <ARRAY><VALUE>value</VALUE></ARRAY>.

A HASH reference is encoded as <HASH><PAIR><KEY>value</KEY><VALUE>value<VALUE></PAIR></HASH> A PAIR may be missing a VALUE which means that it is undefined.

If a value is really the intended value, then it is rendered XML safe by using entity references and no extra space is used. If the value is a reference to something else then the object is converted to XML using extra white space and indentation for easier reading.



Convert XML strings back into objects.


Copyright 2002, Andrew Pitonyak (

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

Modification History

September 10, 2002

Version 1.00 Initial release