XML_Util
[ class tree: XML_Util ] [ index: XML_Util ] [ all elements ]

Source for file example.php

Documentation is available at example.php

  1. <?PHP
  2.     require_once 'XML/Util.php';
  3.     
  4.     /**
  5.     * replacing XML entities
  6.     */
  7.     print "replace XML entities:<br>\n";
  8.     print XML_Util::replaceEntities("This string contains < & >.");
  9.     print "\n<br><br>\n";
  10.  
  11.     /**
  12.     * building XML declaration
  13.     */
  14.     print "building XML declaration:<br>\n";
  15.     print "\n<br><br>\n";
  16.  
  17.     print "building XML declaration with additional attributes:<br>";
  18.     print htmlspecialchars(XML_Util::getXMLDeclaration("1.0""UTF-8"true));
  19.     print "\n<br><br>\n";
  20.  
  21.     /**
  22.     * building document type declaration
  23.     */
  24.     print "building DocType declaration:<br>\n";
  25.     print htmlspecialchars(XML_Util::getDocTypeDeclaration('package''http://pear.php.net/dtd/package-1.0'));
  26.     print "\n<br><br>\n";
  27.  
  28.     print "building DocType declaration with public ID (does not exist):<br>\n";
  29.     print htmlspecialchars(XML_Util::getDocTypeDeclaration('package'array('uri' => 'http://pear.php.net/dtd/package-1.0''id' => '-//PHP//PEAR/DTD PACKAGE 0.1')));
  30.     print "\n<br><br>\n";
  31.  
  32.     print "building DocType declaration with internal DTD:<br>\n";
  33.     print "<pre>";
  34.     print htmlspecialchars(XML_Util::getDocTypeDeclaration('package''http://pear.php.net/dtd/package-1.0''<!ELEMENT additionalInfo (#PCDATA)>'));
  35.     print "</pre>";
  36.     print "\n<br><br>\n";
  37.  
  38.     /**
  39.     * creating an attribute string
  40.     */
  41.     $att = array(
  42.                   "foo"   =>  "bar",
  43.                   "argh"  =>  "tomato"
  44.                 );
  45.  
  46.     print "converting array to string:<br>\n";
  47.     print XML_Util::attributesToString($att);
  48.     print "\n<br><br>\n";
  49.  
  50.  
  51.     /**
  52.     * creating an attribute string with linebreaks
  53.     */
  54.     $att = array(
  55.                   "foo"   =>  "bar",
  56.                   "argh"  =>  "tomato"
  57.                 );
  58.  
  59.     print "converting array to string (including line breaks):<br>\n";
  60.     print "<pre>";
  61.     print XML_Util::attributesToString($atttruetrue);
  62.     print "</pre>";
  63.     print "\n<br><br>\n";
  64.  
  65.  
  66.     /**
  67.     * splitting a qualified tag name
  68.     */
  69.     print "splitting qualified tag name:<br>\n";
  70.     print "<pre>";
  71.     print_r(XML_Util::splitQualifiedName("xslt:stylesheet"));
  72.     print "</pre>";
  73.     print "\n<br>\n";
  74.  
  75.  
  76.     /**
  77.     * splitting a qualified tag name (no namespace)
  78.     */
  79.     print "splitting qualified tag name (no namespace):<br>\n";
  80.     print "<pre>";
  81.     print "</pre>";
  82.     print "\n<br>\n";
  83.  
  84.     /**
  85.     * splitting a qualified tag name (no namespace, but default namespace specified)
  86.     */
  87.     print "splitting qualified tag name (no namespace, but default namespace specified):<br>\n";
  88.     print "<pre>";
  89.     print_r(XML_Util::splitQualifiedName("foo""bar"));
  90.     print "</pre>";
  91.     print "\n<br>\n";
  92.  
  93.     /**
  94.     * verifying XML names
  95.     */
  96.     print "verifying 'My private tag':<br>\n";
  97.     print "<pre>";
  98.     print_r(XML_Util::isValidname('My Private Tag'));
  99.     print "</pre>";
  100.     print "\n<br><br>\n";
  101.     
  102.     print "verifying '-MyTag':<br>\n";
  103.     print "<pre>";
  104.     print_r(XML_Util::isValidname('-MyTag'));
  105.     print "</pre>";
  106.     print "\n<br><br>\n";
  107.  
  108.     /**
  109.     * creating an XML tag
  110.     */
  111.     $tag = array(
  112.                   "namespace"   => "foo",
  113.                   "localPart"   => "bar",
  114.                   "attributes"  => array"key" => "value""argh" => "fruit&vegetable" ),
  115.                   "content"     => "I'm inside the tag"
  116.                 );
  117.  
  118.     print "creating a tag with namespace and local part:<br>";
  119.     print htmlentities(XML_Util::createTagFromArray($tag));
  120.     print "\n<br><br>\n";
  121.  
  122.     /**
  123.     * creating an XML tag
  124.     */
  125.     $tag = array(
  126.                   "qname"        => "foo:bar",
  127.                   "namespaceUri" => "http://foo.com",
  128.                   "attributes"   => array"key" => "value""argh" => "fruit&vegetable" ),
  129.                   "content"      => "I'm inside the tag"
  130.                 );
  131.  
  132.     print "creating a tag with qualified name and namespaceUri:<br>\n";
  133.     print htmlentities(XML_Util::createTagFromArray($tag));
  134.     print "\n<br><br>\n";
  135.  
  136.     /**
  137.     * creating an XML tag
  138.     */
  139.     $tag = array(
  140.                   "qname"        => "bar",
  141.                   "namespaceUri" => "http://foo.com",
  142.                   "attributes"   => array"key" => "value""argh" => "fruit&vegetable" )
  143.                 );
  144.  
  145.     print "creating an empty tag without namespace but namespace Uri:<br>\n";
  146.     print htmlentities(XML_Util::createTagFromArray($tag));
  147.     print "\n<br><br>\n";
  148.  
  149.     /**
  150.     * creating an XML tag with a CData Section
  151.     */
  152.     $tag = array(
  153.                   "qname"        => "foo",
  154.                   "attributes"   => array"key" => "value""argh" => "fruit&vegetable" ),
  155.                   "content"      => "I'm inside the tag"
  156.                 );
  157.  
  158.     print "creating a tag with CData section:<br>\n";
  159.     print "\n<br><br>\n";
  160.  
  161.     /**
  162.     * creating an XML tag with createTag
  163.     */
  164.     print "creating a tag with createTag:<br>";
  165.     print htmlentities(XML_Util::createTag("myNs:myTag"array("foo" => "bar")"This is inside the tag""http://www.w3c.org/myNs#"));
  166.     print "\n<br><br>\n";
  167.  
  168.     
  169.     /**
  170.     * trying to create an XML tag with an array as content
  171.     */
  172.     $tag = array(
  173.                   "qname"        => "bar",
  174.                   "content"      => array"foo" => "bar" )
  175.                 );
  176.     print "trying to create an XML tag with an array as content:<br>\n";
  177.     print "<pre>";
  178.     print "</pre>";
  179.     print "\n<br><br>\n";
  180.     
  181. ?>

Documentation generated on Mon, 11 Mar 2019 10:17:22 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.