53 define(
'XML_UTIL_ERROR_INVALID_CHARS', 51);
 
   58 define(
'XML_UTIL_ERROR_INVALID_START', 52);
 
   63 define(
'XML_UTIL_ERROR_NON_SCALAR_CONTENT', 60);
 
   68 define(
'XML_UTIL_ERROR_NO_TAG_NAME', 61);
 
   73 define(
'XML_UTIL_REPLACE_ENTITIES', 1);
 
   78 define(
'XML_UTIL_CDATA_SECTION', 5);
 
   83 define(
'XML_UTIL_ENTITIES_NONE', 0);
 
   89 define(
'XML_UTIL_ENTITIES_XML', 1);
 
   95 define(
'XML_UTIL_ENTITIES_XML_REQUIRED', 2);
 
  101 define(
'XML_UTIL_ENTITIES_HTML', 3);
 
  106 define(
'XML_UTIL_COLLAPSE_ALL', 1);
 
  111 define(
'XML_UTIL_COLLAPSE_XHTML_ONLY', 2);
 
  180         $encoding = 
'ISO-8859-1')
 
  182         switch ($replaceEntities) {
 
  184             return strtr($string, array(
 
  192             return strtr($string, array(
 
  198             return htmlentities($string, ENT_COMPAT, $encoding);
 
  246         $encoding = 
'ISO-8859-1')
 
  248         switch ($replaceEntities) {
 
  250             return strtr($string, array(
 
  258             return strtr($string, array(
 
  264             return html_entity_decode($string, ENT_COMPAT, $encoding);
 
  293             'version' => $version,
 
  296         if ($encoding !== null) {
 
  297             $attributes[
'encoding'] = $encoding;
 
  300         if ($standalone !== null) {
 
  301             $attributes[
'standalone'] = $standalone ? 
'yes' : 
'no';
 
  304         return sprintf(
'<?xml%s?>', 
 
  330         if (is_array($uri)) {
 
  331             $ref = sprintf(
' PUBLIC "%s" "%s"', $uri[
'id'], $uri[
'uri']);
 
  332         } elseif (!empty($uri)) {
 
  333             $ref = sprintf(
' SYSTEM "%s"', $uri);
 
  338         if (empty($internalDtd)) {
 
  339             return sprintf(
'<!DOCTYPE %s%s>', $root, $ref);
 
  341             return sprintf(
"<!DOCTYPE %s%s [\n%s\n]>", $root, $ref, $internalDtd);
 
  389         if (is_array($sort)) {
 
  390             if (isset($sort[
'multiline'])) {
 
  391                 $multiline = $sort[
'multiline'];
 
  393             if (isset($sort[
'indent'])) {
 
  394                 $indent = $sort[
'indent'];
 
  396             if (isset($sort[
'linebreak'])) {
 
  397                 $multiline = $sort[
'linebreak'];
 
  399             if (isset($sort[
'entities'])) {
 
  400                 $entities = $sort[
'entities'];
 
  402             if (isset($sort[
'sort'])) {
 
  403                 $sort = $sort[
'sort'];
 
  409         if (is_array($attributes) && !empty($attributes)) {
 
  413             if ( !$multiline || count($attributes) == 1) {
 
  414                 foreach ($attributes as $key => $value) {
 
  421                     $string .= 
' ' . $key . 
'="' . $value . 
'"';
 
  425                 foreach ($attributes as $key => $value) {
 
  430                         $string .= 
' ' . $key . 
'="' . $value . 
'"';
 
  433                         $string .= $linebreak . $indent . $key . 
'="' . $value . 
'"';
 
  458                 '/<(area|base(?:font)?|br|col|frame|hr|img|input|isindex|link|meta|' 
  459                 . 
'param)([^>]*)><\/\\1>/s',
 
  463             return preg_replace(
'/<(\w+)([^>]*)><\/\\1>/s', 
'<\\1\\2 />', $xml);
 
  504     function createTag($qname, $attributes = array(), $content = null, 
 
  506         $multiline = 
false, $indent = 
'_auto', $linebreak = 
"\n", 
 
  507         $sortAttributes = 
true)
 
  511             'attributes' => $attributes
 
  515         if ($content !== null) {
 
  516             $tag[
'content'] = $content;
 
  520         if ($namespaceUri !== null) {
 
  521             $tag[
'namespaceUri'] = $namespaceUri;
 
  525             $indent, $linebreak, $sortAttributes);
 
  588         $multiline = 
false, $indent = 
'_auto', $linebreak = 
"\n", 
 
  589         $sortAttributes = 
true)
 
  591         if (isset($tag[
'content']) && !is_scalar($tag[
'content'])) {
 
  596         if (!isset($tag[
'qname']) && !isset($tag[
'localPart'])) {
 
  598                 . 
'(qname) or local tag name (localPart).', 
 
  603         if (!isset($tag[
'attributes']) || !is_array($tag[
'attributes'])) {
 
  604             $tag[
'attributes'] = array();
 
  607         if (isset($tag[
'namespaces'])) {
 
  608             foreach ($tag[
'namespaces'] as $ns => $uri) {
 
  609                 $tag[
'attributes'][
'xmlns:' . $ns] = $uri;
 
  613         if (!isset($tag[
'qname'])) {
 
  617             if (isset($tag[
'namespace']) && !empty($tag[
'namespace'])) {
 
  618                 $tag[
'qname'] = $tag[
'namespace'] . 
':' . $tag[
'localPart'];
 
  620                 $tag[
'qname'] = $tag[
'localPart'];
 
  622         } elseif (isset($tag[
'namespaceUri']) && !isset($tag[
'namespace'])) {
 
  627             $tag[
'localPart'] = $parts[
'localPart'];
 
  628             if (isset($parts[
'namespace'])) {
 
  629                 $tag[
'namespace'] = $parts[
'namespace'];
 
  633         if (isset($tag[
'namespaceUri']) && !empty($tag[
'namespaceUri'])) {
 
  635             if (isset($tag[
'namespace']) && !empty($tag[
'namespace'])) {
 
  636                 $tag[
'attributes'][
'xmlns:' . $tag[
'namespace']] =
 
  637                     $tag[
'namespaceUri'];
 
  640                 $tag[
'attributes'][
'xmlns'] = $tag[
'namespaceUri'];
 
  645         if ($multiline === 
true) {
 
  646             if ($indent === 
'_auto') {
 
  647                 $indent = str_repeat(
' ', (strlen($tag[
'qname'])+2));
 
  653             $sortAttributes, $multiline, $indent, $linebreak, $replaceEntities);
 
  654         if (!isset($tag[
'content']) || (
string)$tag[
'content'] == 
'') {
 
  655             $tag = sprintf(
'<%s%s />', $tag[
'qname'], $attList);
 
  657             switch ($replaceEntities) {
 
  668             $tag = sprintf(
'<%s%s>%s</%s>', $tag[
'qname'], $attList, $tag[
'content'],
 
  701         $multiline = 
false, $indent = 
'_auto', $linebreak = 
"\n", 
 
  702         $sortAttributes = 
true)
 
  705         if (!isset($attributes) || !is_array($attributes)) {
 
  706             $attributes = array();
 
  709         if ($namespaceUri != null) {
 
  714         if ($multiline === 
true) {
 
  715             if ($indent === 
'_auto') {
 
  716                 $indent = str_repeat(
' ', (strlen($qname)+2));
 
  720         if ($namespaceUri != null) {
 
  722             if (isset($parts[
'namespace']) && !empty($parts[
'namespace'])) {
 
  723                 $attributes[
'xmlns:' . $parts[
'namespace']] = $namespaceUri;
 
  726                 $attributes[
'xmlns'] = $namespaceUri;
 
  732             $multiline, $indent, $linebreak);
 
  733         $element = sprintf(
'<%s%s>', $qname, $attList);
 
  756         $element = sprintf(
'</%s>', $qname);
 
  778         $comment = sprintf(
'<!-- %s -->', $content);
 
  800         return sprintf(
'<![CDATA[%s]]>', 
 
  801             preg_replace(
'/\]\]>/', 
']]]]><![CDATA[>', strval(
$data)));
 
  831         if (strstr($qname, 
':')) {
 
  832             $tmp = explode(
':', $qname);
 
  834                 'namespace' => $tmp[0],
 
  835                 'localPart' => $tmp[1]
 
  839             'namespace' => $defaultNs,
 
  840             'localPart' => $qname
 
  874         if (!preg_match(
'/^[[:alpha:]_]$/', $string{0})) {
 
  880         if (!preg_match(
'/^([[:alpha:]_]([[:alnum:]\-\.]*)?:)?[[:alpha:]_]([[:alnum:]\_\-\.]+)?$/',
 
  884                 . 
'chars, period, hyphen, colon and underscores', 
 
  907         require_once 
'PEAR.php';