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

Source for file Util.php

Documentation is available at Util.php

  1. <?PHP
  2. /* vim: set expandtab tabstop=4 shiftwidth=4: */
  3. // +----------------------------------------------------------------------+
  4. // | PHP Version 4                                                        |
  5. // +----------------------------------------------------------------------+
  6. // | Copyright (c) 1997-2002 The PHP Group                                |
  7. // +----------------------------------------------------------------------+
  8. // | This source file is subject to version 2.0 of the PHP license,       |
  9. // | that is bundled with this package in the file LICENSE, and is        |
  10. // | available at through the world-wide-web at                           |
  11. // | http://www.php.net/license/2_02.txt.                                 |
  12. // | If you did not receive a copy of the PHP license and are unable to   |
  13. // | obtain it through the world-wide-web, please send a note to          |
  14. // | license@php.net so we can mail you a copy immediately.               |
  15. // +----------------------------------------------------------------------+
  16. // | Authors: Stephan Schmidt <schst@php-tools.net>                       |
  17. // +----------------------------------------------------------------------+
  18. //
  19. //    $Id: Util.php,v 1.19 2004/05/24 18:58:31 schst Exp $
  20.  
  21. /**
  22.  * error code for invalid chars in XML name
  23.  */
  24. define("XML_UTIL_ERROR_INVALID_CHARS"51);
  25.  
  26. /**
  27.  * error code for invalid chars in XML name
  28.  */
  29. define("XML_UTIL_ERROR_INVALID_START"52);
  30.  
  31. /**
  32.  * error code for non-scalar tag content
  33.  */
  34. define("XML_UTIL_ERROR_NON_SCALAR_CONTENT"60);
  35.     
  36. /**
  37.  * replace XML entities
  38.  */
  39. define("XML_UTIL_REPLACE_ENTITIES"1);
  40.  
  41. /**
  42.  * embedd content in a CData Section
  43.  */
  44. define("XML_UTIL_CDATA_SECTION"2);
  45.  
  46. /**
  47.  * do not replace entitites
  48.  */
  49. define("XML_UTIL_ENTITIES_NONE"0);
  50.  
  51. /**
  52.  * replace all XML entitites
  53.  * This setting will replace <, >, ", ' and &
  54.  */
  55. define("XML_UTIL_ENTITIES_XML"1);
  56.  
  57. /**
  58.  * replace only required XML entitites
  59.  * This setting will replace <, " and &
  60.  */
  61. define("XML_UTIL_ENTITIES_XML_REQUIRED"2);
  62.  
  63. /**
  64.  * replace HTML entitites
  65.  * @link    http://www.php.net/htmlentities
  66.  */
  67. define("XML_UTIL_ENTITIES_HTML"3);
  68.  
  69. /**
  70.  * utility class for working with XML documents
  71.  *
  72.  * @category XML
  73.  * @package  XML_Util
  74.  * @version  0.6.0
  75.  * @author   Stephan Schmidt <schst@php.net>
  76.  */
  77. class XML_Util {
  78.  
  79.    /**
  80.     * return API version
  81.     *
  82.     * @access   public
  83.     * @static
  84.     * @return   string  $version API version
  85.     */
  86.     function apiVersion()
  87.     {
  88.         return "0.6";
  89.     }
  90.  
  91.    /**
  92.     * replace XML entities
  93.     *
  94.     * With the optional second parameter, you may select, which
  95.     * entities should be replaced.
  96.     *
  97.     * <code>
  98.     * require_once 'XML/Util.php';
  99.     * 
  100.     * // replace XML entites:
  101.     * $string = XML_Util::replaceEntities("This string contains < & >.");
  102.     * </code>
  103.     *
  104.     * @access   public
  105.     * @static
  106.     * @param    string  string where XML special chars should be replaced
  107.     * @param    integer setting for entities in attribute values (one of XML_UTIL_ENTITIES_XML, XML_UTIL_ENTITIES_XML_REQUIRED, XML_UTIL_ENTITIES_HTML)
  108.     * @return   string  string with replaced chars
  109.     */
  110.     function replaceEntities($string$replaceEntities = XML_UTIL_ENTITIES_XML)
  111.     {
  112.         switch ($replaceEntities{
  113.             case XML_UTIL_ENTITIES_XML:
  114.                 return strtr($string,array(
  115.                                           '&'  => '&amp;',
  116.                                           '>'  => '&gt;',
  117.                                           '<'  => '&lt;',
  118.                                           '"'  => '&quot;',
  119.                                           '\'' => '&apos;' ));
  120.                 break;
  121.             case XML_UTIL_ENTITIES_XML_REQUIRED:
  122.                 return strtr($string,array(
  123.                                           '&'  => '&amp;',
  124.                                           '<'  => '&lt;',
  125.                                           '"'  => '&quot;' ));
  126.                 break;
  127.             case XML_UTIL_ENTITIES_HTML:
  128.                 return htmlspecialchars($string);
  129.                 break;
  130.         }
  131.         return $string;
  132.     }
  133.  
  134.    /**
  135.     * build an xml declaration
  136.     *
  137.     * <code>
  138.     * require_once 'XML/Util.php';
  139.     * 
  140.     * // get an XML declaration:
  141.     * $xmlDecl = XML_Util::getXMLDeclaration("1.0", "UTF-8", true);
  142.     * </code>
  143.     *
  144.     * @access   public
  145.     * @static
  146.     * @param    string  $version     xml version
  147.     * @param    string  $encoding    character encoding
  148.     * @param    boolean $standAlone  document is standalone (or not)
  149.     * @return   string  $decl xml declaration
  150.     * @uses     XML_Util::attributesToString() to serialize the attributes of the XML declaration
  151.     */
  152.     function getXMLDeclaration($version "1.0"$encoding = null$standalone = null)
  153.     {
  154.         $attributes = array(
  155.                             "version" => $version,
  156.                            );
  157.         // add encoding
  158.         if ($encoding !== null{
  159.             $attributes["encoding"$encoding;
  160.         }
  161.         // add standalone, if specified
  162.         if ($standalone !== null{
  163.             $attributes["standalone"$standalone "yes" "no";
  164.         }
  165.         
  166.         return sprintf("<?xml%s?>"XML_Util::attributesToString($attributesfalse));
  167.     }
  168.  
  169.    /**
  170.     * build a document type declaration
  171.     *
  172.     * <code>
  173.     * require_once 'XML/Util.php';
  174.     * 
  175.     * // get a doctype declaration:
  176.     * $xmlDecl = XML_Util::getDocTypeDeclaration("rootTag","myDocType.dtd");
  177.     * </code>
  178.     *
  179.     * @access   public
  180.     * @static
  181.     * @param    string  $root         name of the root tag
  182.     * @param    string  $uri          uri of the doctype definition (or array with uri and public id)
  183.     * @param    string  $internalDtd  internal dtd entries
  184.     * @return   string  $decl         doctype declaration
  185.     * @since    0.2
  186.     */
  187.     function getDocTypeDeclaration($root$uri = null$internalDtd = null)
  188.     {
  189.         if (is_array($uri)) {
  190.             $ref sprintf' PUBLIC "%s" "%s"'$uri["id"]$uri["uri");
  191.         elseif (!empty($uri)) {
  192.             $ref sprintf' SYSTEM "%s"'$uri );
  193.         else {
  194.             $ref "";
  195.         }
  196.  
  197.         if (empty($internalDtd)) {
  198.             return sprintf("<!DOCTYPE %s%s>"$root$ref);
  199.         else {
  200.             return sprintf("<!DOCTYPE %s%s [\n%s\n]>"$root$ref$internalDtd);
  201.         }
  202.     }
  203.  
  204.    /**
  205.     * create string representation of an attribute list
  206.     *
  207.     * <code>
  208.     * require_once 'XML/Util.php';
  209.     * 
  210.     * // build an attribute string
  211.     * $att = array(
  212.     *              "foo"   =>  "bar",
  213.     *              "argh"  =>  "tomato"
  214.     *            );
  215.     *
  216.     * $attList = XML_Util::attributesToString($att);
  217.     * </code>
  218.     *
  219.     * @access   public
  220.     * @static
  221.     * @param    array         $attributes        attribute array
  222.     * @param    boolean|array$sort              sort attribute list alphabetically, may also be an assoc array containing the keys 'sort', 'multiline', 'indent', 'linebreak' and 'entities'
  223.     * @param    boolean       $multiline         use linebreaks, if more than one attribute is given
  224.     * @param    string        $indent            string used for indentation of multiline attributes
  225.     * @param    string        $linebreak         string used for linebreaks of multiline attributes
  226.     * @param    integer       $entities          setting for entities in attribute values (one of XML_UTIL_ENTITIES_NONE, XML_UTIL_ENTITIES_XML, XML_UTIL_ENTITIES_XML_REQUIRED, XML_UTIL_ENTITIES_HTML)
  227.     * @return   string                           string representation of the attributes
  228.     * @uses     XML_Util::replaceEntities() to replace XML entities in attribute values
  229.     * @todo     allow sort also to be an options array
  230.     */
  231.     function attributesToString($attributes$sort = true$multiline = false$indent '    '$linebreak "\n"$entities = XML_UTIL_ENTITIES_XML)
  232.     {
  233.         /**
  234.          * second parameter may be an array
  235.          */
  236.         if (is_array($sort)) {
  237.             if (isset($sort['multiline'])) {
  238.                 $multiline $sort['multiline'];
  239.             }
  240.             if (isset($sort['indent'])) {
  241.                 $indent $sort['indent'];
  242.             }
  243.             if (isset($sort['linebreak'])) {
  244.                 $multiline $sort['linebreak'];
  245.             }
  246.             if (isset($sort['entities'])) {
  247.                 $entities $sort['entities'];
  248.             }
  249.             if (isset($sort['sort'])) {
  250.                 $sort $sort['sort'];
  251.             else {
  252.                 $sort = true;
  253.             }
  254.         }
  255.         $string '';
  256.         if (is_array($attributes&& !empty($attributes)) {
  257.             if ($sort{
  258.                 ksort($attributes);
  259.             }
  260.             if!$multiline || count($attributes== 1{
  261.                 foreach ($attributes as $key => $value{
  262.                     if ($entities != XML_UTIL_ENTITIES_NONE{
  263.                         $value XML_Util::replaceEntities($value$entities);
  264.                     }
  265.                     $string .= ' '.$key.'="'.$value.'"';
  266.                 }
  267.             else {
  268.                 $first = true;
  269.                 foreach ($attributes as $key => $value{
  270.                     if ($entities != XML_UTIL_ENTITIES_NONE{
  271.                         $value XML_Util::replaceEntities($value$entities);
  272.                     }
  273.                     if ($first{
  274.                         $string .= " ".$key.'="'.$value.'"';
  275.                         $first = false;
  276.                     else {
  277.                         $string .= $linebreak.$indent.$key.'="'.$value.'"';
  278.                     }
  279.                 }
  280.             }
  281.         }
  282.         return $string;
  283.     }
  284.  
  285.    /**
  286.     * create a tag
  287.     *
  288.     * This method will call XML_Util::createTagFromArray(), which
  289.     * is more flexible.
  290.     *
  291.     * <code>
  292.     * require_once 'XML/Util.php';
  293.     * 
  294.     * // create an XML tag:
  295.     * $tag = XML_Util::createTag("myNs:myTag", array("foo" => "bar"), "This is inside the tag", "http://www.w3c.org/myNs#");
  296.     * </code>
  297.     *
  298.     * @access   public
  299.     * @static
  300.     * @param    string  $qname             qualified tagname (including namespace)
  301.     * @param    array   $attributes        array containg attributes
  302.     * @param    mixed   $content 
  303.     * @param    string  $namespaceUri      URI of the namespace
  304.     * @param    integer $replaceEntities   whether to replace XML special chars in content, embedd it in a CData section or none of both
  305.     * @param    boolean $multiline         whether to create a multiline tag where each attribute gets written to a single line
  306.     * @param    string  $indent            string used to indent attributes (_auto indents attributes so they start at the same column)
  307.     * @param    string  $linebreak         string used for linebreaks
  308.     * @return   string  $string            XML tag
  309.     * @see      XML_Util::createTagFromArray()
  310.     * @uses     XML_Util::createTagFromArray() to create the tag
  311.     */
  312.     function createTag($qname$attributes = array()$content = null$namespaceUri = null$replaceEntities = XML_UTIL_REPLACE_ENTITIES$multiline = false$indent "_auto"$linebreak "\n")
  313.     {
  314.         $tag = array(
  315.                      "qname"      => $qname,
  316.                      "attributes" => $attributes
  317.                     );
  318.  
  319.         // add tag content
  320.         if ($content !== null{
  321.             $tag["content"$content;
  322.         }
  323.         
  324.         // add namespace Uri
  325.         if ($namespaceUri !== null{
  326.             $tag["namespaceUri"$namespaceUri;
  327.         }
  328.  
  329.         return XML_Util::createTagFromArray($tag$replaceEntities$multiline$indent$linebreak);
  330.     }
  331.  
  332.    /**
  333.     * create a tag from an array
  334.     * this method awaits an array in the following format
  335.     * <pre>
  336.     * array(
  337.     *  "qname"        => $qname         // qualified name of the tag
  338.     *  "namespace"    => $namespace     // namespace prefix (optional, if qname is specified or no namespace)
  339.     *  "localpart"    => $localpart,    // local part of the tagname (optional, if qname is specified)
  340.     *  "attributes"   => array(),       // array containing all attributes (optional)
  341.     *  "content"      => $content,      // tag content (optional)
  342.     *  "namespaceUri" => $namespaceUri  // namespaceUri for the given namespace (optional)
  343.     *   )
  344.     * </pre>
  345.     *
  346.     * <code>
  347.     * require_once 'XML/Util.php';
  348.     * 
  349.     * $tag = array(
  350.     *           "qname"        => "foo:bar",
  351.     *           "namespaceUri" => "http://foo.com",
  352.     *           "attributes"   => array( "key" => "value", "argh" => "fruit&vegetable" ),
  353.     *           "content"      => "I'm inside the tag",
  354.     *            );
  355.     * // creating a tag with qualified name and namespaceUri
  356.     * $string = XML_Util::createTagFromArray($tag);
  357.     * </code>
  358.     *
  359.     * @access   public
  360.     * @static
  361.     * @param    array   $tag               tag definition
  362.     * @param    integer $replaceEntities   whether to replace XML special chars in content, embedd it in a CData section or none of both
  363.     * @param    boolean $multiline         whether to create a multiline tag where each attribute gets written to a single line
  364.     * @param    string  $indent            string used to indent attributes (_auto indents attributes so they start at the same column)
  365.     * @param    string  $linebreak         string used for linebreaks
  366.     * @return   string  $string            XML tag
  367.     * @see      XML_Util::createTag()
  368.     * @uses     XML_Util::attributesToString() to serialize the attributes of the tag
  369.     * @uses     XML_Util::splitQualifiedName() to get local part and namespace of a qualified name
  370.     */
  371.     function createTagFromArray($tag$replaceEntities = XML_UTIL_REPLACE_ENTITIES$multiline = false$indent "_auto"$linebreak "\n" )
  372.     {
  373.         if (isset($tag["content"]&& !is_scalar($tag["content"])) {
  374.             return XML_Util::raiseError"Supplied non-scalar value as tag content"XML_UTIL_ERROR_NON_SCALAR_CONTENT );
  375.         }
  376.  
  377.         // if no attributes hav been set, use empty attributes
  378.         if (!isset($tag["attributes"]|| !is_array($tag["attributes"])) {
  379.             $tag["attributes"= array();
  380.         }
  381.         
  382.         // qualified name is not given
  383.         if (!isset($tag["qname"])) {
  384.             // check for namespace
  385.             if (isset($tag["namespace"]&& !empty($tag["namespace"])) {
  386.                 $tag["qname"$tag["namespace"].":".$tag["localPart"];
  387.             else {
  388.                 $tag["qname"$tag["localPart"];
  389.             }
  390.         // namespace URI is set, but no namespace
  391.         elseif (isset($tag["namespaceUri"]&& !isset($tag["namespace"])) {
  392.             $parts XML_Util::splitQualifiedName($tag["qname"]);
  393.             $tag["localPart"$parts["localPart"];
  394.             if (isset($parts["namespace"])) {
  395.                 $tag["namespace"$parts["namespace"];
  396.             }
  397.         }
  398.  
  399.         if (isset($tag["namespaceUri"]&& !empty($tag["namespaceUri"])) {
  400.             // is a namespace given
  401.             if (isset($tag["namespace"]&& !empty($tag["namespace"])) {
  402.                 $tag["attributes"]["xmlns:".$tag["namespace"]] $tag["namespaceUri"];
  403.             else {
  404.                 // define this Uri as the default namespace
  405.                 $tag["attributes"]["xmlns"$tag["namespaceUri"];
  406.             }
  407.         }
  408.  
  409.         // check for multiline attributes
  410.         if ($multiline === true{
  411.             if ($indent === "_auto"{
  412.                 $indent str_repeat(" "(strlen($tag["qname"])+2));
  413.             }
  414.         }
  415.         
  416.         // create attribute list
  417.         $attList    =   XML_Util::attributesToString($tag["attributes"]true$multiline$indent$linebreak );
  418.         if (!isset($tag["content"]|| (string)$tag["content"== ''{
  419.             $tag    =   sprintf("<%s%s />"$tag["qname"]$attList);
  420.         else {
  421.             if ($replaceEntities == XML_UTIL_REPLACE_ENTITIES{
  422.                 $tag["content"XML_Util::replaceEntities($tag["content"]);
  423.             elseif ($replaceEntities == XML_UTIL_CDATA_SECTION{
  424.                 $tag["content"XML_Util::createCDataSection($tag["content"]);
  425.             }
  426.             $tag    =   sprintf("<%s%s>%s</%s>"$tag["qname"]$attList$tag["content"]$tag["qname");
  427.         }        
  428.         return  $tag;
  429.     }
  430.  
  431.    /**
  432.     * create a start element
  433.     *
  434.     * <code>
  435.     * require_once 'XML/Util.php';
  436.     * 
  437.     * // create an XML start element:
  438.     * $tag = XML_Util::createStartElement("myNs:myTag", array("foo" => "bar") ,"http://www.w3c.org/myNs#");
  439.     * </code>
  440.     *
  441.     * @access   public
  442.     * @static
  443.     * @param    string  $qname             qualified tagname (including namespace)
  444.     * @param    array   $attributes        array containg attributes
  445.     * @param    string  $namespaceUri      URI of the namespace
  446.     * @param    boolean $multiline         whether to create a multiline tag where each attribute gets written to a single line
  447.     * @param    string  $indent            string used to indent attributes (_auto indents attributes so they start at the same column)
  448.     * @param    string  $linebreak         string used for linebreaks
  449.     * @return   string  $string            XML start element
  450.     * @see      XML_Util::createEndElement(), XML_Util::createTag()
  451.     */
  452.     function createStartElement($qname$attributes = array()$namespaceUri = null$multiline = false$indent '_auto'$linebreak "\n")
  453.     {
  454.         // if no attributes hav been set, use empty attributes
  455.         if (!isset($attributes|| !is_array($attributes)) {
  456.             $attributes = array();
  457.         }
  458.         
  459.         if ($namespaceUri != null{
  460.             $parts XML_Util::splitQualifiedName($qname);
  461.         }
  462.  
  463.         // check for multiline attributes
  464.         if ($multiline === true{
  465.             if ($indent === "_auto"{
  466.                 $indent str_repeat(" "(strlen($qname)+2));
  467.             }
  468.         }
  469.  
  470.         if ($namespaceUri != null{
  471.             // is a namespace given
  472.             if (isset($parts["namespace"]&& !empty($parts["namespace"])) {
  473.                 $attributes["xmlns:".$parts["namespace"]] $namespaceUri;
  474.             else {
  475.                 // define this Uri as the default namespace
  476.                 $attributes["xmlns"$namespaceUri;
  477.             }
  478.         }
  479.  
  480.         // create attribute list
  481.         $attList    =   XML_Util::attributesToString($attributestrue$multiline$indent$linebreak);
  482.         $element    =   sprintf("<%s%s>"$qname$attList);
  483.         return  $element;
  484.     }
  485.  
  486.    /**
  487.     * create an end element
  488.     *
  489.     * <code>
  490.     * require_once 'XML/Util.php';
  491.     * 
  492.     * // create an XML start element:
  493.     * $tag = XML_Util::createEndElement("myNs:myTag");
  494.     * </code>
  495.     *
  496.     * @access   public
  497.     * @static
  498.     * @param    string  $qname             qualified tagname (including namespace)
  499.     * @return   string  $string            XML end element
  500.     * @see      XML_Util::createStartElement(), XML_Util::createTag()
  501.     */
  502.     function createEndElement($qname)
  503.     {
  504.         $element    =   sprintf("</%s>"$qname);
  505.         return  $element;
  506.     }
  507.     
  508.    /**
  509.     * create an XML comment
  510.     *
  511.     * <code>
  512.     * require_once 'XML/Util.php';
  513.     * 
  514.     * // create an XML start element:
  515.     * $tag = XML_Util::createComment("I am a comment");
  516.     * </code>
  517.     *
  518.     * @access   public
  519.     * @static
  520.     * @param    string  $content           content of the comment
  521.     * @return   string  $comment           XML comment
  522.     */
  523.     function createComment($content)
  524.     {
  525.         $comment    =   sprintf("<!-- %s -->"$content);
  526.         return  $comment;
  527.     }
  528.     
  529.    /**
  530.     * create a CData section
  531.     *
  532.     * <code>
  533.     * require_once 'XML/Util.php';
  534.     * 
  535.     * // create a CData section
  536.     * $tag = XML_Util::createCDataSection("I am content.");
  537.     * </code>
  538.     *
  539.     * @access   public
  540.     * @static
  541.     * @param    string  $data              data of the CData section
  542.     * @return   string  $string            CData section with content
  543.     */
  544.     function createCDataSection($data)
  545.     {
  546.         return  sprintf("<![CDATA[%s]]>"$data);
  547.     }
  548.  
  549.    /**
  550.     * split qualified name and return namespace and local part
  551.     *
  552.     * <code>
  553.     * require_once 'XML/Util.php';
  554.     * 
  555.     * // split qualified tag
  556.     * $parts = XML_Util::splitQualifiedName("xslt:stylesheet");
  557.     * </code>
  558.     * the returned array will contain two elements:
  559.     * <pre>
  560.     * array(
  561.     *       "namespace" => "xslt",
  562.     *       "localPart" => "stylesheet"
  563.     *      );
  564.     * </pre>
  565.     *
  566.     * @access public
  567.     * @static
  568.     * @param  string    $qname      qualified tag name
  569.     * @param  string    $defaultNs  default namespace (optional)
  570.     * @return array     $parts      array containing namespace and local part
  571.     */
  572.     function splitQualifiedName($qname$defaultNs = null)
  573.     {
  574.         if (strstr($qname':')) {
  575.             $tmp explode(":"$qname);
  576.             return array(
  577.                           "namespace" => $tmp[0],
  578.                           "localPart" => $tmp[1]
  579.                         );
  580.         }
  581.         return array(
  582.                       "namespace" => $defaultNs,
  583.                       "localPart" => $qname
  584.                     );
  585.     }
  586.  
  587.    /**
  588.     * check, whether string is valid XML name
  589.     *
  590.     * <p>XML names are used for tagname, attribute names and various
  591.     * other, lesser known entities.</p>
  592.     * <p>An XML name may only consist of alphanumeric characters,
  593.     * dashes, undescores and periods, and has to start with a letter
  594.     * or an underscore.
  595.     * </p>
  596.     *
  597.     * <code>
  598.     * require_once 'XML/Util.php';
  599.     * 
  600.     * // verify tag name
  601.     * $result = XML_Util::isValidName("invalidTag?");
  602.     * if (XML_Util::isError($result)) {
  603.     *    print "Invalid XML name: " . $result->getMessage();
  604.     * }
  605.     * </code>
  606.     *
  607.     * @access  public
  608.     * @static
  609.     * @param   string  $string string that should be checked
  610.     * @return  mixed   $valid  true, if string is a valid XML name, PEAR error otherwise
  611.     * @todo    support for other charsets
  612.     */
  613.     function isValidName($string)
  614.     {
  615.         // check for invalid chars
  616.         if (!preg_match("/^[[:alnum:]_\-.]$/"$string{0})) {
  617.             return XML_Util::raiseError"XML names may only start with letter or underscore"XML_UTIL_ERROR_INVALID_START );
  618.         }
  619.         
  620.         // check for invalid chars
  621.         if (!preg_match("/^([a-zA-Z_]([a-zA-Z0-9_\-\.]*)?:)?[a-zA-Z_]([a-zA-Z0-9_\-\.]+)?$/"$string)) {
  622.             return XML_Util::raiseError"XML names may only contain alphanumeric chars, period, hyphen, colon and underscores"XML_UTIL_ERROR_INVALID_CHARS );
  623.          }
  624.         // XML name is valid
  625.         return true;
  626.     }
  627.  
  628.    /**
  629.     * replacement for XML_Util::raiseError
  630.     *
  631.     * Avoids the necessity to always require
  632.     * PEAR.php
  633.     *
  634.     * @access   public
  635.     * @param    string      error message
  636.     * @param    integer     error code
  637.     * @return   object PEAR_Error 
  638.     */
  639.     function raiseError($msg$code)
  640.     {
  641.         require_once 'PEAR.php';
  642.         return PEAR::raiseError($msg$code);
  643.     }
  644. }
  645. ?>

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