[RfC] XML_Serializer
| From: | Stephan Schmidt | Date: | Mon, 28 Jul 2003 19:21:23 +0000 |
| Subject: | [RfC] XML_Serializer | ||
| Groups: | php.pear.dev | ||
| Request: | Send a blank email to pear-dev+get-18840@lists.php.net to get a copy of this message | ||
Hi,
I'd like to propose a new XML helper class entitled XML_Serilaizer.
It provides a static method that serializes any data structure in an XML
format. Currently arrays and objects are supported. Let's give a small
example:
Let's say, you get a PEAR::DB error and serialize it, this will be the
result:
<db_error>
<error_message_prefix/>
<mode>1</mode>
<level>1024</level>
<code>-24</code>
<message>DB Error: connect failed</message>
<userinfo> [nativecode=Access denied for user:
'root@localhost' (Using password: YES)] ...</userinfo>
<backtrace>
<unnamedItem>
<file>C:\php4\pear\DB.php</file>
<line>642</line>
<function>pear_error</function>
<class>db_error</class>
<type>-></type>
<args>
<unnamedItem>DB Error: connect failed</unnamedItem>
<unnamedItem>-24</unnamedItem>
<unnamedItem>1</unnamedItem>
<unnamedItem>1024</unnamedItem>
<unnamedItem> [nativecode=Access denied for user:
'root@localhost' (Using password: YES)]</unnamedItem>
</args>
</unnamedItem>
<unnamedItem>
<file>C:\php4\pear\PEAR.php</file>
<line>522</line>
<function>db_error</function>
<class>db_error</class>
<type>-></type>
<args>
<unnamedItem>-24</unnamedItem>
<unnamedItem>1</unnamedItem>
<unnamedItem>1024</unnamedItem>
<unnamedItem> [nativecode=Access denied for user:
'root@localhost' (Using password: YES)]</unnamedItem>
</args>
</unnamedItem>
[some XML left out]
</backtrace>
<callback/>
</db_error>
Serializing errors may not be useful, but you can use this class to
generate any XML document. Use your favorite data structure to build the
document in memeory and serialize itm when your done.
Furthermore the class provides methods to convert an array to a list of
attributes, replace XML entities in any string and other useful methods.
This could be used as a helper class for various XML, so there's no
redundancy in the PEAR XML classes.
Indentation, line breaks and tagnames can be configured...
The sourcecode of the first alpha version can be found at:
http://www.php-tools.de/PEAR/XML/XML_Serializer.phps
Examples can be found at:
http://www.php-tools.de/PEAR/XML/examples/serializeArray.php
http://www.php-tools.de/PEAR/XML/examples/serializeArray.phps
and
http://www.php-tools.de/PEAR/XML/examples/serializeObject.php
http://www.php-tools.de/PEAR/XML/examples/serializeObject.phps
I propose this class as I need the functionality for other XML related
classes, I'm working on.
Future versions will support other data stuctures, a method to validate
an XML tag name and other commonly used XML related methods.
Waiting for your comments.
Stephan