* @license http://opensource.org/licenses/bsd-license New BSD License
* @version CVS: $Id$
* @link http://pear.php.net/package/XML_Util
*/
/**
* set error level
*/
error_reporting(E_ALL);
require_once 'XML/Util.php';
/**
* replacing XML entities
*/
print 'replace XML entities:
';
print XML_Util::replaceEntities('This string contains < & >.');
print "\n
\n";
/**
* reversing XML entities
*/
print 'replace XML entities:
';
print XML_Util::reverseEntities('This string contains < & >.');
print "\n
\n";
/**
* building XML declaration
*/
print 'building XML declaration:
';
print htmlspecialchars(XML_Util::getXMLDeclaration());
print "\n
\n";
print 'building XML declaration with additional attributes:
';
print htmlspecialchars(XML_Util::getXMLDeclaration('1.0', 'UTF-8', true));
print "\n
\n";
/**
* building document type declaration
*/
print 'building DocType declaration:
';
print htmlspecialchars(XML_Util::getDocTypeDeclaration('package',
'http://pear.php.net/dtd/package-1.0'));
print "\n
\n";
print 'building DocType declaration with public ID (does not exist):
';
print htmlspecialchars(XML_Util::getDocTypeDeclaration('package',
array('uri' => 'http://pear.php.net/dtd/package-1.0',
'id' => '-//PHP//PEAR/DTD PACKAGE 0.1')));
print "\n
\n";
print 'building DocType declaration with internal DTD:
';
print '';
print htmlspecialchars(XML_Util::getDocTypeDeclaration('package',
'http://pear.php.net/dtd/package-1.0',
''));
print '
';
print "\n
\n";
/**
* creating an attribute string
*/
$att = array(
'foo' => 'bar',
'argh' => 'tomato'
);
print 'converting array to string:
';
print XML_Util::attributesToString($att);
print "\n
\n";
/**
* creating an attribute string with linebreaks
*/
$att = array(
'foo' => 'bar',
'argh' => 'tomato'
);
print 'converting array to string (including line breaks):
';
print '';
print XML_Util::attributesToString($att, true, true);
print '
';
print "\n
\n";
/**
* splitting a qualified tag name
*/
print 'splitting qualified tag name:
';
print '';
print_r(XML_Util::splitQualifiedName('xslt:stylesheet'));
print '
';
print "\n
\n";
/**
* splitting a qualified tag name (no namespace)
*/
print 'splitting qualified tag name (no namespace):
';
print '';
print_r(XML_Util::splitQualifiedName('foo'));
print '
';
print "\n
\n";
/**
* splitting a qualified tag name (no namespace, but default namespace specified)
*/
print 'splitting qualified tag name '
. '(no namespace, but default namespace specified):
';
print '';
print_r(XML_Util::splitQualifiedName('foo', 'bar'));
print '
';
print "\n
\n";
/**
* verifying XML names
*/
print 'verifying \'My private tag\':
';
print '';
print_r(XML_Util::isValidname('My Private Tag'));
print '
';
print "\n
\n";
print 'verifying \'-MyTag\':
';
print '';
print_r(XML_Util::isValidname('-MyTag'));
print '
';
print "\n
\n";
/**
* creating an XML tag
*/
$tag = array(
'namespace' => 'foo',
'localPart' => 'bar',
'attributes' => array('key' => 'value', 'argh' => 'fruit&vegetable'),
'content' => 'I\'m inside the tag'
);
print 'creating a tag with namespace and local part:
';
print htmlentities(XML_Util::createTagFromArray($tag));
print "\n
\n";
/**
* creating an XML tag
*/
$tag = array(
'qname' => 'foo:bar',
'namespaceUri' => 'http://foo.com',
'attributes' => array('key' => 'value', 'argh' => 'fruit&vegetable'),
'content' => 'I\'m inside the tag'
);
print 'creating a tag with qualified name and namespaceUri:
';
print htmlentities(XML_Util::createTagFromArray($tag));
print "\n
\n";
/**
* creating an XML tag
*/
$tag = array(
'qname' => 'bar',
'namespaceUri' => 'http://foo.com',
'attributes' => array('key' => 'value', 'argh' => 'fruit&vegetable')
);
print 'creating an empty tag without namespace but namespace Uri:
';
print htmlentities(XML_Util::createTagFromArray($tag));
print "\n
\n";
/**
* creating an XML tag with more namespaces
*/
$tag = array(
'namespace' => 'foo',
'localPart' => 'bar',
'attributes' => array('key' => 'value', 'argh' => 'fruit&vegetable'),
'content' => 'I\'m inside the tag',
'namespaces' => array(
'bar' => 'http://bar.com',
'pear' => 'http://pear.php.net',
)
);
print 'creating an XML tag with more namespaces:
';
print htmlentities(XML_Util::createTagFromArray($tag));
print "\n
\n";
/**
* creating an XML tag with a CData Section
*/
$tag = array(
'qname' => 'foo',
'attributes' => array('key' => 'value', 'argh' => 'fruit&vegetable'),
'content' => 'I\'m inside the tag'
);
print 'creating a tag with CData section:
';
print htmlentities(XML_Util::createTagFromArray($tag, XML_UTIL_CDATA_SECTION));
print "\n
\n";
/**
* creating an XML tag with a CData Section
*/
$tag = array(
'qname' => 'foo',
'attributes' => array('key' => 'value', 'argh' => 'tt'),
'content' =>
'Also XHTML-tags can be created '
. 'and HTML entities can be replaced <>.'
);
print 'creating a tag with HTML entities:
';
print htmlentities(XML_Util::createTagFromArray($tag, XML_UTIL_ENTITIES_HTML));
print "\n
\n";
/**
* creating an XML tag with createTag
*/
print 'creating a tag with createTag:
';
print htmlentities(XML_Util::createTag('myNs:myTag',
array('foo' => 'bar'),
'This is inside the tag',
'http://www.w3c.org/myNs#'));
print "\n
\n";
/**
* trying to create an XML tag with an array as content
*/
$tag = array(
'qname' => 'bar',
'content' => array('foo' => 'bar')
);
print 'trying to create an XML tag with an array as content:
';
print '';
print_r(XML_Util::createTagFromArray($tag));
print '
';
print "\n
\n";
/**
* trying to create an XML tag without a name
*/
$tag = array(
'attributes' => array('foo' => 'bar'),
);
print 'trying to create an XML tag without a name:
';
print '';
print_r(XML_Util::createTagFromArray($tag));
print '
';
print "\n
\n";
?>