cvs: peardoc /en/package/xml xml-serializer.xml /en/package/xml/xml-serializer/xml-serializer examples.xml

From: Date: Thu, 01 Jun 2006 05:08:08 +0000
Subject: cvs: peardoc /en/package/xml xml-serializer.xml /en/package/xml/xml-serializer/xml-serializer examples.xml
Groups: php.pear.doc 
Request: Send a blank email to pear-doc+get-7966@lists.php.net to get a copy of this message
moosh Thu Jun 1 05:08:08 2006 UTC Added files: /peardoc/en/package/xml/xml-serializer/xml-serializer examples.xml Modified files: /peardoc/en/package/xml xml-serializer.xml Log: - include and begin to comment the example of packages for serializer functionalities

http://cvs.php.net/viewcvs.cgi/peardoc/en/package/xml/xml-serializer.xml?r1=1.5&r2=1.6&diff_format=u Index: peardoc/en/package/xml/xml-serializer.xml diff -u peardoc/en/package/xml/xml-serializer.xml:1.5 peardoc/en/package/xml/xml-serializer.xml:1.6 --- peardoc/en/package/xml/xml-serializer.xml:1.5 Wed May 26 13:21:25 2004 +++ peardoc/en/package/xml/xml-serializer.xml Thu Jun 1 05:08:07 2006 @@ -1,4 +1,4 @@ -<!-- $Revision: 1.5 $ --> +<!-- $Revision: 1.6 $ --> <sect1 id="package.xml.xml-serializer"> <title>XML_Serializer</title> &package.xml.xml-serializer.intro; @@ -37,6 +37,7 @@ &package.xml.xml-serializer.xml-serializer.getserializeddata; &package.xml.xml-serializer.xml-serializer.resetoptions; &package.xml.xml-serializer.xml-serializer.setoption; + &package.xml.xml-serializer.xml-serializer.examples; <refentry id="package.xml.xml-serializer.xml-unserializer-summary"> <refnamediv> <refname>Class Summary <classname>XML_Unserializer</classname></refname> http://cvs.php.net/viewcvs.cgi/peardoc/en/package/xml/xml-serializer/xml-serializer/examples.xml?view=markup&rev=1.1 Index: peardoc/en/package/xml/xml-serializer/xml-serializer/examples.xml +++ peardoc/en/package/xml/xml-serializer/xml-serializer/examples.xml <!-- $Revision: 1.1 $ --> <!-- $Author: moosh $ --> <refentry id="package.xml.xml-serializer.xml-serializer.examples"> <refnamediv> <refname>Example</refname> <refpurpose>Example for the usage of XML_Serializer</refpurpose> </refnamediv> <refsect1 id="package.xml.xml-serializer.xml-serializer.examples.example1"> <title>Build a simple XML document</title> <para> Example that uses the returnResult option to directly return the serialized XML document in the serialize() method. </para> <para> In this example look at theses 3 lines. </para> <programlisting role="php"> <![CDATA[$serializer = &new XML_Serializer($options); $foo = PEAR::raiseError('Just a test', 1234); $result = $serializer->serialize($foo); ]]> </programlisting> <programlisting role="php"> <![CDATA[error_reporting(E_ALL); require_once 'XML/Serializer.php'; $options = array( XML_SERIALIZER_OPTION_INDENT => ' ', XML_SERIALIZER_OPTION_RETURN_RESULT => true ); $serializer = &new XML_Serializer($options); $foo = PEAR::raiseError('Just a test', 1234); $result = $serializer->serialize($foo); echo '<pre>'; echo htmlspecialchars($result); echo '</pre>'; ]]> </programlisting> <para> And this is the result </para> <programlisting role="xml"> <![CDATA[<pear_error> <error_message_prefix /> <mode>1</mode> <level>1024</level> <code>1234</code> <message>Just a test</message> <userinfo /> <backtrace> <XML_Serializer_Tag> <file>pathToMypear\PEAR.php</file> <line>566</line> <function>pear_error</function> <class>pear_error</class> <type>-&gt;</type> <args> <XML_Serializer_Tag>Just a test</XML_Serializer_Tag> <XML_Serializer_Tag>1234</XML_Serializer_Tag> <XML_Serializer_Tag>1</XML_Serializer_Tag> <XML_Serializer_Tag>1024</XML_Serializer_Tag> <XML_Serializer_Tag /> </args> </XML_Serializer_Tag> <XML_Serializer_Tag> <file>pathToMyDocRoot\cvs.php.net\pear\xml_serializer\examples\serializeandreturn.php</file> <line>19</line> <function>raiseerror</function> <class>pear</class> <type>::</type> <args> <XML_Serializer_Tag>Just a test</XML_Serializer_Tag> <XML_Serializer_Tag>1234</XML_Serializer_Tag> </args> </XML_Serializer_Tag> </backtrace> <callback /> </pear_error>]]> </programlisting> <para> You can find the last version of this source code in the package : serializeAndReturn.php </para> </refsect1> <refsect1 id="package.xml.xml-serializer.xml-serializer.examples.exampleRDF"> <title>Build a RDF document</title> <para> This example shows how to create an RDF document with a few lines of code. This can also be done with mode => simplexml. </para> <para> In this example look at theses 3 lines. </para> <programlisting role="php"> <![CDATA[ $serializer = new XML_Serializer($options); $result = $serializer->serialize($rdf); echo htmlentities($serializer->getSerializedData()); ]]> </programlisting> <programlisting role="php"> <![CDATA[ /** * @see serializeIndexedArray.php */ error_reporting(E_ALL); require_once 'XML/Serializer.php'; $options = array( "indent" => " ", "linebreak" => "\n", "typeHints" => false, "addDecl" => true, "encoding" => "UTF-8", "rootName" => "rdf:RDF", "rootAttributes" => array("version" => "0.91"), "defaultTagName" => "item", "attributesArray" => "_attributes" ); $serializer = new XML_Serializer($options); $rdf = array( "channel" => array( "title" => "Example RDF channel", "link" => "http://www.php-tools.de", "image" => array( "title" => "Example image", "url" => "http://www.php-tools.de/image.gif", "link" => "http://www.php-tools.de" ), "_attributes" => array( "rdf:about" => "http://example.com/foobar.html" ), array( "title" => "Example item", "link" => "http://example.com", "_attributes" => array( "rdf:about" => "http://example.com/foobar.html" ) ), array( "title" => "Another item", "link" => "http://example.com", "_attributes" => array( "rdf:about" => "http://example.com/foobar.html" ) ), array( "title" => "I think you get it...", "link" => "http://example.com", "_attributes" => array( "rdf:about" => "http://example.com/foobar.html" ) ) ) ); $result = $serializer->serialize($rdf); if( $result === true ) { echo "<pre>"; echo htmlentities($serializer->getSerializedData()); echo "</pre>"; } ]]> </programlisting> <para> And this is the result </para> <programlisting role="xml"> <![CDATA[<?xml version="1.0" encoding="UTF-8"?> <rdf:RDF version="0.91"> <channel rdf:about="http://example.com/foobar.html"> <title>Example RDF channel</title> <link>http://www.php-tools.de</link> <image> <title>Example image</title> <url>http://www.php-tools.de/image.gif</url> <link>http://www.php-tools.de</link> </image> <item rdf:about="http://example.com/foobar.html"> <title>Example item</title> <link>http://example.com</link> </item> <item rdf:about="http://example.com/foobar.html"> <title>Another item</title> <link>http://example.com</link> </item> <item rdf:about="http://example.com/foobar.html"> <title>I think you get it...</title> <link>http://example.com</link> </item> </channel> </rdf:RDF>]]> </programlisting> <para> You can find the last version of this source code in the package : serializeRDF.php </para> <para> Note : if you search how to parse (read) an RDF/RSS document, look at XML_RSS package. </para> </refsect1> <refsect1 id="package.xml.xml-serializer.xml-serializer.examples.exampleDtd"> <title>Build a XML document with a DTD</title> <para> This example shows how to add a DocType Declaration to the XML document </para> <para> In this example look at theses 3 lines. </para> <programlisting role="php"> <![CDATA[ $serializer = new XML_Serializer($options); $result = $serializer->serialize($rdf); echo htmlentities($serializer->getSerializedData()); ]]> </programlisting> <programlisting role="php"> <![CDATA[ error_reporting(E_ALL); require_once 'XML/Serializer.php'; $options = array( "indent" => " ", "linebreak" => "\n", "addDecl" => true, "addDoctype" => true, "doctype" => array( 'uri' => 'http://pear.php.net/dtd/package-1.0', 'id' => '-//PHP//PEAR/DTD PACKAGE 0.1' ) ); $serializer = new XML_Serializer($options); $foo = PEAR::raiseError("Just a test", 1234); $result = $serializer->serialize($foo); if( $result === true ) { echo '<pre>'; echo htmlentities($serializer->getSerializedData()); echo '</pre>'; } ]]> </programlisting> <para> And this is the result </para> <programlisting role="xml"> <![CDATA[<?xml version="1.0"?> <!DOCTYPE pear_error PUBLIC "-//PHP//PEAR/DTD PACKAGE 0.1" "http://pear.php.net/dtd/package-1.0"> <pear_error> <error_message_prefix /> <mode>1</mode> <level>1024</level> <code>1234</code> <message>Just a test</message> <userinfo /> <backtrace> <XML_Serializer_Tag> <file>pathToMyPear\PEAR.php</file> <line>566</line> <function>pear_error</function> <class>pear_error</class> <type>-&gt;</type> <args> <XML_Serializer_Tag>Just a test</XML_Serializer_Tag> <XML_Serializer_Tag>1234</XML_Serializer_Tag> <XML_Serializer_Tag>1</XML_Serializer_Tag> <XML_Serializer_Tag>1024</XML_Serializer_Tag> <XML_Serializer_Tag /> </args> </XML_Serializer_Tag> <XML_Serializer_Tag> <file>pathToMyDocumentRoot\cvs.php.net\pear\xml_serializer\examples\serializewithdtd.php</file> <line>24</line> <function>raiseerror</function> <class>pear</class> <type>::</type> <args> <XML_Serializer_Tag>Just a test</XML_Serializer_Tag> <XML_Serializer_Tag>1234</XML_Serializer_Tag> </args> </XML_Serializer_Tag> </backtrace> <callback /> </pear_error>]]> </programlisting> <para> You can find the last version of this source code in the package : serializeWithDTD.php </para> </refsect1> </refentry> <!-- Keep this comment at the end of the file Local variables: mode: sgml sgml-omittag:t sgml-shorttag:t sgml-minimize-attributes:nil sgml-always-quote-attributes:t sgml-indent-step:1 sgml-indent-data:t sgml-parent-document:nil sgml-default-dtd-file:"../../../../manual.ced" sgml-exposed-tags:nil sgml-local-catalogs:nil sgml-local-ecat-files:nil End: vim600: syn=xml fen fdm=syntax fdl=2 si vim: et tw=78 syn=sgml vi: ts=1 sw=1 -->
« previous php.pear.doc (#7966) next »