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.
convert_entity_references_to_characters(@strings_with_entity_refs)
Change '&' to '&', '<' to '<', '>' to '>', '"' to '``', and ''' to '''``.
The calling parameters are modfied
convert_xml_characters_to_entity_references(@strings_needing_entity_refs)
Change '&' to '&', '<' to '<', '>' to '>', '``' to '"', and '''`` to ''',
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.
object_to_xml(@objects_to_transform)
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.
xml_to_object(@xml_strings_to_convert_to_objects)
Convert XML strings back into objects.
Copyright 2002, Andrew Pitonyak (perlboy@pitonyak.org)
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Version 1.00 Initial release