Example #1
0
<?php

require_once 'XML/FastCreate.php';
error_reporting(E_ALL);
// You can also use the factory() method to make this object
$x =& XML_FastCreate::factory('Text', array('doctype' => XML_FASTCREATE_DOCTYPE_XHTML_1_0_STRICT, 'dtd' => '../dtd/xhtml_1_0_strict.dtd'));
$x->html($x->head($x->title('Example 2 - XML_FastCreate'), $x->style(array('type' => 'text/css', 'media' => 'all'), $x->cdata("@import url('example.css');"))), $x->body($x->div($x->h1("XML_FastCreate - Example 2"), $x->h3("Driver : " . $x->_driver), $x->h3("Control XML with a DTD file"), $x->p($x->a(array('href' => $_SERVER['PHP_SELF'] . 's'), "PHP source file")), $x->p($x->a(array('href' => './'), "Others examples"))), $x->div($x->span(array('hello' => 'world'), "Examples of errors DTD validation"), $x->foo()), $x->div($x->hr(), $x->a(array('href' => 'http://pear.php.net'), $x->img(array('src' => 'http://pear.php.net/gifs/pear-power.png', 'alt' => 'PEAR Logo'))))));
$err = $x->toXML();
// Print DTD errors
if (PEAR::isError($err)) {
    echo "<div id='dtd_errors'>" . nl2br(htmlSpecialChars($err->getMessage())) . "</div>";
}
Example #2
0
<?php

/**
 * XML_FastCreate : Simple Example 
 *
 * This is the little example describe in the documentation
 *
 */
require_once 'XML/FastCreate.php';
$x =& XML_FastCreate::factory('Text');
$x->html($x->head($x->title("A simple XHTML page")), $x->body($x->div($x->h1('Example'), $x->br(), $x->a(array('href' => 'http://pear.php.net'), 'PEAR WebSite'))));
// Write output
$x->toXML();
Example #3
0
<?php

require_once 'XML/FastCreate.php';
error_reporting(E_ALL);
// Create XML without DTD control (no dependencies)
$x =& XML_FastCreate::factory('Text', array('doctype' => XML_FASTCREATE_DOCTYPE_XHTML_1_0_STRICT));
$x->html($x->head($x->title('Example 1 - XML_FastCreate'), $x->style(array('type' => 'text/css', 'media' => 'all'), $x->cdata("@import url('example.css');"))), $x->body($x->div($x->h1("XML_FastCreate - Example 1"), $x->h3("Driver : " . $x->_driver), $x->h3("Package overview"), $x->comment("Example of 'comment()'", $x->span("Hello")), $x->p($x->a(array('href' => $_SERVER['PHP_SELF'] . 's'), "PHP source file")), $x->p($x->a(array('href' => './'), "Others examples")), $x->ul($x->li($x->h3("Fast creation of valid XML contents :"), $x->h4("Simply use the method of the tag name :"), $x->p(array('class' => 'code'), '$x->span("hi")'), $x->p(array('class' => 'html'), '= <span>hi</span>'), $x->h4("This is an 'overload' mapping of xml() method :"), $x->p(array('class' => 'code'), '$x->xml("span", "hi")'), $x->xml('p', array('class' => 'html'), '= <span>hi</span>'), $x->h4("You can add attributes on the 1st parameter :"), $x->p(array('class' => 'code'), '$x->span(array(\'class\'=>\'test\'), "hi")'), $x->p(array('class' => 'html'), '= <span class="test">hi<span>'), $x->h4("You can add tags inside your tag :"), $x->p(array('class' => 'code'), '$x->span("XML", ', $x->br(), $x->noquote('&nbsp;&nbsp;'), '$x->i("Fast"),', $x->br(), $x->noquote('&nbsp;&nbsp;'), '$x->b("Create")', $x->br(), ')'), $x->p(array('class' => 'html'), '= <span>XML<i>Fast</i><b>Create</b></span>'), $x->h4('Make empty tag or alone tag :'), $x->p(array('class' => 'code'), '$x->span(\'\')'), $x->p(array('class' => 'html'), '= <span></span>'), $x->p(array('class' => 'code'), '$x->br()'), $x->p(array('class' => 'html'), '= <br />'), $x->h4("You can make multiples parts and gather them later :"), $x->p(array('class' => 'code'), '$body = $x->div( $x->p("hello") );', $x->br(), '$x->body($body);'), $x->h4('List of methods :'), $x->p($x->span(array('class' => 'code'), '$x->quote("a > b")'), ' To convert HTML special tags (if quote option is false)'), $x->p($x->span(array('class' => 'code'), '$x->noquote("&nbsp;")'), ' To not convert HTML special tags (if quote option is true)'), $x->p($x->span(array('class' => 'code'), '$x->comment( $x->p("hello") )'), ' To make XML comments'), $x->p($x->span(array('class' => 'code'), '$x->cdata("alert(\\"Let\'s Go !\\");")'), ' To make CDATA section'), $x->p($x->span(array('class' => 'code'), '$x->getXML()'), ' To get the XML output'), $x->p($x->span(array('class' => 'code'), '$x->isValid()'), ' To control your XML with the DTD'), $x->p($x->span(array('class' => 'code'), '$x->toXML()'), ' To write and control XML'), $x->p($x->span(array('class' => 'code'), '$x->importXML()'), ' To convert XML text to XML driver format'), $x->p($x->span(array('class' => 'code'), '$x->exportXML()'), ' To convert XML driver format to XML text')), $x->li($x->h3("XML conform to the DTD option"), $x->h4("Choose your DTD tool :"), $x->p("Use the internal tool", $x->span(array('class' => 'require'), "( Require XML_DTD package )")), $x->p("Or define an external program (like xmllint)")), $x->li($x->h3("Independant output data"), $x->h4("Choose the output driver to use :"), $x->p("Text : return strings"), $x->p("XML_Tree : return XML_Tree objects", $x->span(array('class' => 'require'), "( Require XML_Tree package )")), $x->p("Or make your own ! :-)")), $x->li($x->h3("XML Translation option"), $x->h4("You can define tags to translate :"), $x->p(array('class' => 'code'), '$x->news(', $x->br(), $x->noquote('&nbsp;&nbsp;'), '$x->title("Title"),', $x->br(), $x->noquote('&nbsp;&nbsp;'), '$x->desc("Description")', $x->br(), ')'), $x->p('Replaced by :'), $x->p(array('class' => 'html'), '<div class="news">', $x->br(), $x->noquote('&nbsp;&nbsp;'), '<h1><span>Title</span></h1>', $x->br(), $x->noquote('&nbsp;&nbsp;'), '<p>Description</p>', $x->br(), '</div>'), $x->h4("Translate declaration is very easy :"), $x->p(array('class' => 'code'), "'translate' => array(", $x->br(), $x->noquote('&nbsp;&nbsp;'), "'news' => array('<div class=\"news\">', '</div>'),", $x->br(), $x->noquote('&nbsp;&nbsp;'), "'title' => array('<h1><span>', '</span></h1>'),", $x->br(), $x->noquote('&nbsp;&nbsp;'), "'desc' => array('<p>', '</p>'),", $x->br(), ')'), $x->p("You can also use shortcuts :"), $x->p(array('class' => 'code'), "'news' => array('<div class=\"news\">', '</div>')", $x->br(), "shortcut : ", "'news' => array()"), $x->p(array('class' => 'code'), "'desc' => array('<p>', '</p>')", $x->br(), "shortcut : ", "'desc' => array('p')"), $x->h4("Prefix tag by '_' to ignore translation :"), $x->p(array('class' => 'code'), '$x->title("Title")'), $x->p(array('class' => 'html'), '= <h1><span>Title</span></h1>'), $x->p(array('class' => 'code'), '$x->_title("Title")'), $x->p(array('class' => 'html'), '= <title>Title</title>')), $x->li($x->h3("Others options"), $x->h4("Auto-quote attributes and contents"), $x->p("Attributes and contents are automatically quoted, but you " . 'can set option \'quote\' to false and use $x->quote()'), $x->h4("Indentation option"), $x->p("Set the 'indent' option to true to make XML indentation", $x->span(array('class' => 'require'), '( Require XML_Beautifier package )')), $x->h4("Write your XML output into a file"), $x->p("Set the the destination file in the 'file' option"), $x->h4("Driver output options"), $x->p("Each driver has these basic options :"), $x->p("'version' To set the xml version (default = '1.0')"), $x->p("'encoding' To set the xml encoding (default = 'UTF-8')"), $x->p("'standalone' To set the xml standalone (default = 'no')"), $x->p("'doctype' To set the doctype (doctype constants exists)"), $x->p("'quote' To quote attributes and contents (default = true)"), $x->h4("With Zend Optimizer, the overload system will crash !"), $x->p("But you can replace overloading by a tags list", $x->a(array('href' => 'example5.php'), "(see Example 5)"))), $x->li($x->h3("Convert your HTML easily to FastCreate syntax !"), $x->h4("The script can convert HTML file to FastCreate syntax"), $x->p("Give the name of the HTML file and the output file"), $x->h4("Or just convert your HTML selection under your editor"), $x->p("Select the HTML text, call the macro and your selected" . " text will be rewrited to FastCreate syntax !"))), $x->hr(), $x->a(array('href' => 'http://pear.php.net'), $x->img(array('src' => 'http://pear.php.net/gifs/pear-power.png', 'alt' => 'PEAR Logo'))))));
$x->toXML();
Example #4
0
<?php

require_once 'XML/FastCreate.php';
error_reporting(E_ALL);
// Create XML with DTD control
$x =& XML_FastCreate::factory('Text', array('doctype' => XML_FASTCREATE_DOCTYPE_XHTML_1_0_STRICT, 'translate' => array('news' => array(), 'desc' => array('p'), 'title' => array('<h1 class="title"><span>', '</span></h1>'), 'date' => array('<span class="date">', '</span>'))));
$x->html($x->head($x->_title('Example 4 - XML_FastCreate'), $x->style(array('type' => 'text/css', 'media' => 'all'), $x->cdata("@import url('example.css');"))), $x->body($x->div($x->h1("XML_FastCreate - Example 4"), $x->h3("Make XML Translations"), $x->p($x->a(array('href' => $_SERVER['PHP_SELF'] . 's'), "PHP source file")), $x->p($x->a(array('href' => './'), "Others examples")), $x->news($x->title('PHP 4.3.6 released!'), $x->date('[15-Apr-2004]'), $x->desc('The PHP Development Team is proud to announce the ' . 'release of ', $x->a(array('href' => 'http://www.php.net/downloads.php'), 'PHP 4.3.6'), '. This is is a bug fix release whose primary goal is ' . 'to address two bugs which may result in crashes in ' . 'PHP builds with thread-safety enabled. All users of ' . 'PHP in a threaded environment (Windows) are strongly ' . 'encouraged to upgrade to this release.', $x->br(), $x->br(), 'All in all this release fixes approximately 25 bugs ' . 'that have been discovered since the 4.3.5 release. ' . 'For a full list of changes in PHP 4.3.6, see the ', $x->a(array('href' => 'http://www.php.net/ChangeLog-4.php#4.3.6'), 'ChangeLog.'))), $x->news($x->title('Second PHP Marathon announced'), $x->date('[06-Apr-2004]'), $x->desc('DotGeek.org is proud to announce the', $x->a(array('href' => 'http://marathon.dotgeek.org/'), 'second PHP Programming Marathon'), ' to be held on the 24 April 2004. Instead of receiving ' . 'the problems and composing your solutions offline, it ' . 'all takes place online and within a specific timeframe. ' . 'The Marathon is kindly sponsored by Zend Technologies ' . 'and will now feature a problem on PHP 5. Participation ' . 'is free of charge.')), $x->hr(), $x->a(array('href' => 'http://pear.php.net'), $x->img(array('src' => 'http://pear.php.net/gifs/pear-power.png', 'alt' => 'PEAR Logo'))))));
$x->toXML();
Example #5
0
<?php

require_once 'XML/FastCreate.php';
error_reporting(E_ALL);
// Create XML with the XML_Tree Driver
$x =& XML_FastCreate::factory('XML_Tree', array('doctype' => XML_FASTCREATE_DOCTYPE_XHTML_1_0_STRICT, 'file' => XML_FASTCREATE_FILE, 'exec' => XML_FASTCREATE_EXEC, 'indent' => true));
$x->html($x->head($x->title('Example 3 - XML_FastCreate')), $x->body($x->div($x->h1("XML_FastCreate - Example 3"), $x->h3("Driver : " . $x->_driver), $x->h3("Control XML with an external DTD validator"), $x->h3("Make output indentation"), $x->p($x->a(array('href' => $_SERVER['PHP_SELF'] . 's'), "PHP source file")), $x->p($x->a(array('href' => './'), "Others examples"))), $x->div($x->span(array('hello' => 'world'), "Examples of errors DTD validation"), $x->foo()), $x->div($x->hr(), $x->a(array('href' => 'http://pear.php.net'), $x->img(array('src' => 'http://pear.php.net/gifs/pear-power.png', 'alt' => 'PEAR Logo'))))));
$err = $x->toXML();
// Print DTD errors
if (PEAR::isError($err)) {
    echo nl2br(htmlSpecialChars($err->getMessage()));
}