ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
All Data Structures Namespaces Files Functions Variables Modules Pages
XML_Util Class Reference
+ Collaboration diagram for XML_Util:

Static Public Member Functions

 apiVersion ()
 return API version More...
 
 replaceEntities ($string, $replaceEntities=XML_UTIL_ENTITIES_XML, $encoding='ISO-8859-1')
 replace XML entities More...
 
 reverseEntities ($string, $replaceEntities=XML_UTIL_ENTITIES_XML, $encoding='ISO-8859-1')
 reverse XML entities More...
 
 getXMLDeclaration ($version='1.0', $encoding=null, $standalone=null)
 build an xml declaration More...
 
 getDocTypeDeclaration ($root, $uri=null, $internalDtd=null)
 build a document type declaration More...
 
 attributesToString ($attributes, $sort=true, $multiline=false, $indent=' ', $linebreak="\, $entities=XML_UTIL_ENTITIES_XML)
 create string representation of an attribute list More...
 
 collapseEmptyTags ($xml, $mode=XML_UTIL_COLLAPSE_ALL)
 Collapses empty tags. More...
 
 createTag ($qname, $attributes=array(), $content=null, $namespaceUri=null, $replaceEntities=XML_UTIL_REPLACE_ENTITIES, $multiline=false, $indent='_auto', $linebreak="\, $sortAttributes=true)
 create a tag More...
 
 createTagFromArray ($tag, $replaceEntities=XML_UTIL_REPLACE_ENTITIES, $multiline=false, $indent='_auto', $linebreak="\, $sortAttributes=true)
 create a tag from an array this method awaits an array in the following format More...
 
 createStartElement ($qname, $attributes=array(), $namespaceUri=null, $multiline=false, $indent='_auto', $linebreak="\, $sortAttributes=true)
 create a start element More...
 
 createEndElement ($qname)
 create an end element More...
 
 createComment ($content)
 create an XML comment More...
 
 createCDataSection ($data)
 create a CData section More...
 
 splitQualifiedName ($qname, $defaultNs=null)
 split qualified name and return namespace and local part More...
 
 isValidName ($string)
 check, whether string is valid XML name More...
 
 raiseError ($msg, $code)
 replacement for XML_Util::raiseError More...
 

Detailed Description

Definition at line 125 of file Util.php.

Member Function Documentation

◆ apiVersion()

XML_Util::apiVersion ( )
static

return API version

Returns
string $version API version public

Definition at line 134 of file Util.php.

135  {
136  return '1.1';
137  }

◆ attributesToString()

XML_Util::attributesToString (   $attributes,
  $sort = true,
  $multiline = false,
  $indent = '    ',
  $linebreak = "\n",
  $entities = XML_UTIL_ENTITIES_XML 
)
static

create string representation of an attribute list

require_once 'XML/Util.php';

// build an attribute string $att = array( 'foo' => 'bar', 'argh' => 'tomato' );

$attList = XML_Util::attributesToString($att);

Parameters
array$attributesattribute array
bool | array$sortsort attribute list alphabetically, may also be an assoc array containing the keys 'sort', 'multiline', 'indent', 'linebreak' and 'entities'
bool$multilineuse linebreaks, if more than one attribute is given
string$indentstring used for indentation of multiline attributes
string$linebreakstring used for linebreaks of multiline attributes
int$entitiessetting for entities in attribute values (one of XML_UTIL_ENTITIES_NONE, XML_UTIL_ENTITIES_XML, XML_UTIL_ENTITIES_XML_REQUIRED, XML_UTIL_ENTITIES_HTML)
Returns
string string representation of the attributes public replaceEntities() to replace XML entities in attribute values
Todo:
allow sort also to be an options array

Definition at line 383 of file Util.php.

References replaceEntities(), XML_UTIL_CDATA_SECTION, XML_UTIL_ENTITIES_NONE, and XML_UTIL_ENTITIES_XML.

Referenced by createStartElement(), createTagFromArray(), and getXMLDeclaration().

385  {
386  /*
387  * second parameter may be an array
388  */
389  if (is_array($sort)) {
390  if (isset($sort['multiline'])) {
391  $multiline = $sort['multiline'];
392  }
393  if (isset($sort['indent'])) {
394  $indent = $sort['indent'];
395  }
396  if (isset($sort['linebreak'])) {
397  $multiline = $sort['linebreak'];
398  }
399  if (isset($sort['entities'])) {
400  $entities = $sort['entities'];
401  }
402  if (isset($sort['sort'])) {
403  $sort = $sort['sort'];
404  } else {
405  $sort = true;
406  }
407  }
408  $string = '';
409  if (is_array($attributes) && !empty($attributes)) {
410  if ($sort) {
411  ksort($attributes);
412  }
413  if ( !$multiline || count($attributes) == 1) {
414  foreach ($attributes as $key => $value) {
415  if ($entities != XML_UTIL_ENTITIES_NONE) {
416  if ($entities === XML_UTIL_CDATA_SECTION) {
417  $entities = XML_UTIL_ENTITIES_XML;
418  }
419  $value = XML_Util::replaceEntities($value, $entities);
420  }
421  $string .= ' ' . $key . '="' . $value . '"';
422  }
423  } else {
424  $first = true;
425  foreach ($attributes as $key => $value) {
426  if ($entities != XML_UTIL_ENTITIES_NONE) {
427  $value = XML_Util::replaceEntities($value, $entities);
428  }
429  if ($first) {
430  $string .= ' ' . $key . '="' . $value . '"';
431  $first = false;
432  } else {
433  $string .= $linebreak . $indent . $key . '="' . $value . '"';
434  }
435  }
436  }
437  }
438  return $string;
439  }
const XML_UTIL_ENTITIES_XML
replace all XML entitites This setting will replace <, >, ", &#39; and &
Definition: Util.php:89
const XML_UTIL_ENTITIES_NONE
do not replace entitites
Definition: Util.php:83
replaceEntities($string, $replaceEntities=XML_UTIL_ENTITIES_XML, $encoding='ISO-8859-1')
replace XML entities
Definition: Util.php:179
const XML_UTIL_CDATA_SECTION
embedd content in a CData Section
Definition: Util.php:78
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ collapseEmptyTags()

XML_Util::collapseEmptyTags (   $xml,
  $mode = XML_UTIL_COLLAPSE_ALL 
)
static

Collapses empty tags.

Parameters
string$xmlXML
int$modeWhether to collapse all empty tags (XML_UTIL_COLLAPSE_ALL) or only XHTML (XML_UTIL_COLLAPSE_XHTML_ONLY) ones.
Returns
string XML public
Todo:
PEAR CS - unable to avoid "space after open parens" error in the IF branch

Definition at line 454 of file Util.php.

References XML_UTIL_COLLAPSE_XHTML_ONLY.

455  {
456  if ($mode == XML_UTIL_COLLAPSE_XHTML_ONLY) {
457  return preg_replace(
458  '/<(area|base(?:font)?|br|col|frame|hr|img|input|isindex|link|meta|'
459  . 'param)([^>]*)><\/\\1>/s',
460  '<\\1\\2 />',
461  $xml);
462  } else {
463  return preg_replace('/<(\w+)([^>]*)><\/\\1>/s', '<\\1\\2 />', $xml);
464  }
465  }
const XML_UTIL_COLLAPSE_XHTML_ONLY
Collapse only empty XHTML tags that have no end tag.
Definition: Util.php:111

◆ createCDataSection()

XML_Util::createCDataSection (   $data)
static

create a CData section

require_once 'XML/Util.php';

// create a CData section $tag = XML_Util::createCDataSection('I am content.');

Parameters
string$datadata of the CData section
Returns
string CData section with content public

Definition at line 798 of file Util.php.

References $data.

Referenced by createTagFromArray().

799  {
800  return sprintf('<![CDATA[%s]]>',
801  preg_replace('/\]\]>/', ']]]]><![CDATA[>', strval($data)));
802 
803  }
+ Here is the caller graph for this function:

◆ createComment()

XML_Util::createComment (   $content)
static

create an XML comment

require_once 'XML/Util.php';

// create an XML start element: $tag = XML_Util::createComment('I am a comment');

Parameters
string$contentcontent of the comment
Returns
string XML comment public

Definition at line 776 of file Util.php.

References $comment.

777  {
778  $comment = sprintf('<!-- %s -->', $content);
779  return $comment;
780  }
$comment
Definition: buildRTE.php:83

◆ createEndElement()

XML_Util::createEndElement (   $qname)
static

create an end element

require_once 'XML/Util.php';

// create an XML start element: $tag = XML_Util::createEndElement('myNs:myTag');

Parameters
string$qnamequalified tagname (including namespace)
Returns
string XML end element public
See also
createStartElement(), createTag()

Definition at line 754 of file Util.php.

755  {
756  $element = sprintf('</%s>', $qname);
757  return $element;
758  }

◆ createStartElement()

XML_Util::createStartElement (   $qname,
  $attributes = array(),
  $namespaceUri = null,
  $multiline = false,
  $indent = '_auto',
  $linebreak = "\n",
  $sortAttributes = true 
)
static

create a start element

require_once 'XML/Util.php';

// create an XML start element: $tag = XML_Util::createStartElement('myNs:myTag', array('foo' => 'bar') ,'http://www.w3c.org/myNs#');

Parameters
string$qnamequalified tagname (including namespace)
array$attributesarray containg attributes
string$namespaceUriURI of the namespace
bool$multilinewhether to create a multiline tag where each attribute gets written to a single line
string$indentstring used to indent attributes (_auto indents attributes so they start at the same column)
string$linebreakstring used for linebreaks
bool$sortAttributesWhether to sort the attributes or not
Returns
string XML start element public
See also
createEndElement(), createTag()

Definition at line 700 of file Util.php.

References attributesToString(), and splitQualifiedName().

703  {
704  // if no attributes hav been set, use empty attributes
705  if (!isset($attributes) || !is_array($attributes)) {
706  $attributes = array();
707  }
708 
709  if ($namespaceUri != null) {
710  $parts = XML_Util::splitQualifiedName($qname);
711  }
712 
713  // check for multiline attributes
714  if ($multiline === true) {
715  if ($indent === '_auto') {
716  $indent = str_repeat(' ', (strlen($qname)+2));
717  }
718  }
719 
720  if ($namespaceUri != null) {
721  // is a namespace given
722  if (isset($parts['namespace']) && !empty($parts['namespace'])) {
723  $attributes['xmlns:' . $parts['namespace']] = $namespaceUri;
724  } else {
725  // define this Uri as the default namespace
726  $attributes['xmlns'] = $namespaceUri;
727  }
728  }
729 
730  // create attribute list
731  $attList = XML_Util::attributesToString($attributes, $sortAttributes,
732  $multiline, $indent, $linebreak);
733  $element = sprintf('<%s%s>', $qname, $attList);
734  return $element;
735  }
splitQualifiedName($qname, $defaultNs=null)
split qualified name and return namespace and local part
Definition: Util.php:829
attributesToString($attributes, $sort=true, $multiline=false, $indent=' ', $linebreak="\, $entities=XML_UTIL_ENTITIES_XML)
create string representation of an attribute list
Definition: Util.php:383
+ Here is the call graph for this function:

◆ createTag()

XML_Util::createTag (   $qname,
  $attributes = array(),
  $content = null,
  $namespaceUri = null,
  $replaceEntities = XML_UTIL_REPLACE_ENTITIES,
  $multiline = false,
  $indent = '_auto',
  $linebreak = "\n",
  $sortAttributes = true 
)
static

create a tag

This method will call XML_Util::createTagFromArray(), which is more flexible.

require_once 'XML/Util.php';

// create an XML tag: $tag = XML_Util::createTag('myNs:myTag', array('foo' => 'bar'), 'This is inside the tag', 'http://www.w3c.org/myNs#');

Parameters
string$qnamequalified tagname (including namespace)
array$attributesarray containg attributes
mixed$contentthe content
string$namespaceUriURI of the namespace
int$replaceEntitieswhether to replace XML special chars in content, embedd it in a CData section or none of both
bool$multilinewhether to create a multiline tag where each attribute gets written to a single line
string$indentstring used to indent attributes (_auto indents attributes so they start at the same column)
string$linebreakstring used for linebreaks
bool$sortAttributesWhether to sort the attributes or not
Returns
string XML tag public
See also
createTagFromArray() createTagFromArray() to create the tag

Definition at line 504 of file Util.php.

References createTagFromArray().

508  {
509  $tag = array(
510  'qname' => $qname,
511  'attributes' => $attributes
512  );
513 
514  // add tag content
515  if ($content !== null) {
516  $tag['content'] = $content;
517  }
518 
519  // add namespace Uri
520  if ($namespaceUri !== null) {
521  $tag['namespaceUri'] = $namespaceUri;
522  }
523 
524  return XML_Util::createTagFromArray($tag, $replaceEntities, $multiline,
525  $indent, $linebreak, $sortAttributes);
526  }
createTagFromArray($tag, $replaceEntities=XML_UTIL_REPLACE_ENTITIES, $multiline=false, $indent='_auto', $linebreak="\, $sortAttributes=true)
create a tag from an array this method awaits an array in the following format
Definition: Util.php:587
+ Here is the call graph for this function:

◆ createTagFromArray()

XML_Util::createTagFromArray (   $tag,
  $replaceEntities = XML_UTIL_REPLACE_ENTITIES,
  $multiline = false,
  $indent = '_auto',
  $linebreak = "\n",
  $sortAttributes = true 
)
static

create a tag from an array this method awaits an array in the following format

array(
    // qualified name of the tag
    'qname' => $qname
    // namespace prefix (optional, if qname is specified or no namespace)
    'namespace' => $namespace
    // local part of the tagname (optional, if qname is specified)
    'localpart' => $localpart,
    // array containing all attributes (optional)
    'attributes' => array(),
    // tag content (optional)
    'content' => $content,
    // namespaceUri for the given namespace (optional)
    'namespaceUri' => $namespaceUri 
)

require_once 'XML/Util.php';

$tag = array( 'qname' => 'foo:bar', 'namespaceUri' => 'http://foo.com', 'attributes' => array('key' => 'value', 'argh' => 'fruit&vegetable'), 'content' => 'I\'m inside the tag', ); // creating a tag with qualified name and namespaceUri $string = XML_Util::createTagFromArray($tag);

Parameters
array$tagtag definition
int$replaceEntitieswhether to replace XML special chars in content, embedd it in a CData section or none of both
bool$multilinewhether to create a multiline tag where each attribute gets written to a single line
string$indentstring used to indent attributes (_auto indents attributes so they start at the same column)
string$linebreakstring used for linebreaks
bool$sortAttributesWhether to sort the attributes or not
Returns
string XML tag public
See also
createTag() attributesToString() to serialize the attributes of the tag splitQualifiedName() to get local part and namespace of a qualified name createCDataSection() raiseError()

Definition at line 587 of file Util.php.

References attributesToString(), createCDataSection(), raiseError(), replaceEntities(), splitQualifiedName(), XML_UTIL_CDATA_SECTION, XML_UTIL_ENTITIES_NONE, XML_UTIL_ERROR_NO_TAG_NAME, and XML_UTIL_ERROR_NON_SCALAR_CONTENT.

Referenced by createTag().

590  {
591  if (isset($tag['content']) && !is_scalar($tag['content'])) {
592  return XML_Util::raiseError('Supplied non-scalar value as tag content',
594  }
595 
596  if (!isset($tag['qname']) && !isset($tag['localPart'])) {
597  return XML_Util::raiseError('You must either supply a qualified name '
598  . '(qname) or local tag name (localPart).',
600  }
601 
602  // if no attributes hav been set, use empty attributes
603  if (!isset($tag['attributes']) || !is_array($tag['attributes'])) {
604  $tag['attributes'] = array();
605  }
606 
607  if (isset($tag['namespaces'])) {
608  foreach ($tag['namespaces'] as $ns => $uri) {
609  $tag['attributes']['xmlns:' . $ns] = $uri;
610  }
611  }
612 
613  if (!isset($tag['qname'])) {
614  // qualified name is not given
615 
616  // check for namespace
617  if (isset($tag['namespace']) && !empty($tag['namespace'])) {
618  $tag['qname'] = $tag['namespace'] . ':' . $tag['localPart'];
619  } else {
620  $tag['qname'] = $tag['localPart'];
621  }
622  } elseif (isset($tag['namespaceUri']) && !isset($tag['namespace'])) {
623  // namespace URI is set, but no namespace
624 
625  $parts = XML_Util::splitQualifiedName($tag['qname']);
626 
627  $tag['localPart'] = $parts['localPart'];
628  if (isset($parts['namespace'])) {
629  $tag['namespace'] = $parts['namespace'];
630  }
631  }
632 
633  if (isset($tag['namespaceUri']) && !empty($tag['namespaceUri'])) {
634  // is a namespace given
635  if (isset($tag['namespace']) && !empty($tag['namespace'])) {
636  $tag['attributes']['xmlns:' . $tag['namespace']] =
637  $tag['namespaceUri'];
638  } else {
639  // define this Uri as the default namespace
640  $tag['attributes']['xmlns'] = $tag['namespaceUri'];
641  }
642  }
643 
644  // check for multiline attributes
645  if ($multiline === true) {
646  if ($indent === '_auto') {
647  $indent = str_repeat(' ', (strlen($tag['qname'])+2));
648  }
649  }
650 
651  // create attribute list
652  $attList = XML_Util::attributesToString($tag['attributes'],
653  $sortAttributes, $multiline, $indent, $linebreak, $replaceEntities);
654  if (!isset($tag['content']) || (string)$tag['content'] == '') {
655  $tag = sprintf('<%s%s />', $tag['qname'], $attList);
656  } else {
657  switch ($replaceEntities) {
659  break;
661  $tag['content'] = XML_Util::createCDataSection($tag['content']);
662  break;
663  default:
664  $tag['content'] = XML_Util::replaceEntities($tag['content'],
665  $replaceEntities);
666  break;
667  }
668  $tag = sprintf('<%s%s>%s</%s>', $tag['qname'], $attList, $tag['content'],
669  $tag['qname']);
670  }
671  return $tag;
672  }
const XML_UTIL_ERROR_NO_TAG_NAME
error code for missing tag name
Definition: Util.php:68
splitQualifiedName($qname, $defaultNs=null)
split qualified name and return namespace and local part
Definition: Util.php:829
createCDataSection($data)
create a CData section
Definition: Util.php:798
const XML_UTIL_ERROR_NON_SCALAR_CONTENT
error code for non-scalar tag content
Definition: Util.php:63
raiseError($msg, $code)
replacement for XML_Util::raiseError
Definition: Util.php:905
const XML_UTIL_ENTITIES_NONE
do not replace entitites
Definition: Util.php:83
replaceEntities($string, $replaceEntities=XML_UTIL_ENTITIES_XML, $encoding='ISO-8859-1')
replace XML entities
Definition: Util.php:179
attributesToString($attributes, $sort=true, $multiline=false, $indent=' ', $linebreak="\, $entities=XML_UTIL_ENTITIES_XML)
create string representation of an attribute list
Definition: Util.php:383
const XML_UTIL_CDATA_SECTION
embedd content in a CData Section
Definition: Util.php:78
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getDocTypeDeclaration()

XML_Util::getDocTypeDeclaration (   $root,
  $uri = null,
  $internalDtd = null 
)
static

build a document type declaration

require_once 'XML/Util.php';

// get a doctype declaration: $xmlDecl = XML_Util::getDocTypeDeclaration('rootTag','myDocType.dtd');

Parameters
string$rootname of the root tag
string$uriuri of the doctype definition (or array with uri and public id)
string$internalDtdinternal dtd entries
Returns
string doctype declaration public
Since
0.2

Definition at line 328 of file Util.php.

329  {
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);
334  } else {
335  $ref = '';
336  }
337 
338  if (empty($internalDtd)) {
339  return sprintf('<!DOCTYPE %s%s>', $root, $ref);
340  } else {
341  return sprintf("<!DOCTYPE %s%s [\n%s\n]>", $root, $ref, $internalDtd);
342  }
343  }

◆ getXMLDeclaration()

XML_Util::getXMLDeclaration (   $version = '1.0',
  $encoding = null,
  $standalone = null 
)
static

build an xml declaration

require_once 'XML/Util.php';

// get an XML declaration: $xmlDecl = XML_Util::getXMLDeclaration('1.0', 'UTF-8', true);

Parameters
string$versionxml version
string$encodingcharacter encoding
bool$standalonedocument is standalone (or not)
Returns
string xml declaration public attributesToString() to serialize the attributes of the XML declaration

Definition at line 289 of file Util.php.

References attributesToString().

291  {
292  $attributes = array(
293  'version' => $version,
294  );
295  // add encoding
296  if ($encoding !== null) {
297  $attributes['encoding'] = $encoding;
298  }
299  // add standalone, if specified
300  if ($standalone !== null) {
301  $attributes['standalone'] = $standalone ? 'yes' : 'no';
302  }
303 
304  return sprintf('<?xml%s?>',
305  XML_Util::attributesToString($attributes, false));
306  }
attributesToString($attributes, $sort=true, $multiline=false, $indent=' ', $linebreak="\, $entities=XML_UTIL_ENTITIES_XML)
create string representation of an attribute list
Definition: Util.php:383
+ Here is the call graph for this function:

◆ isValidName()

XML_Util::isValidName (   $string)
static

check, whether string is valid XML name

XML names are used for tagname, attribute names and various other, lesser known entities.

An XML name may only consist of alphanumeric characters, dashes, undescores and periods, and has to start with a letter or an underscore.

require_once 'XML/Util.php';

// verify tag name $result = XML_Util::isValidName('invalidTag?'); if (is_a($result, 'PEAR_Error')) { print 'Invalid XML name: ' . $result->getMessage(); }

Parameters
string$stringstring that should be checked
Returns
mixed true, if string is a valid XML name, PEAR error otherwise public
Todo:

support for other charsets

PEAR CS - unable to avoid 85-char limit on second preg_match

Definition at line 871 of file Util.php.

References raiseError(), XML_UTIL_ERROR_INVALID_CHARS, and XML_UTIL_ERROR_INVALID_START.

872  {
873  // check for invalid chars
874  if (!preg_match('/^[[:alpha:]_]$/', $string{0})) {
875  return XML_Util::raiseError('XML names may only start with letter '
876  . 'or underscore', XML_UTIL_ERROR_INVALID_START);
877  }
878 
879  // check for invalid chars
880  if (!preg_match('/^([[:alpha:]_]([[:alnum:]\-\.]*)?:)?[[:alpha:]_]([[:alnum:]\_\-\.]+)?$/',
881  $string)
882  ) {
883  return XML_Util::raiseError('XML names may only contain alphanumeric '
884  . 'chars, period, hyphen, colon and underscores',
886  }
887  // XML name is valid
888  return true;
889  }
const XML_UTIL_ERROR_INVALID_START
error code for invalid chars in XML name
Definition: Util.php:58
raiseError($msg, $code)
replacement for XML_Util::raiseError
Definition: Util.php:905
const XML_UTIL_ERROR_INVALID_CHARS
error code for invalid chars in XML name
Definition: Util.php:53
+ Here is the call graph for this function:

◆ raiseError()

XML_Util::raiseError (   $msg,
  $code 
)
static

replacement for XML_Util::raiseError

Avoids the necessity to always require PEAR.php

Parameters
string$msgerror message
int$codeerror code
Returns
PEAR_Error public
Todo:
PEAR CS - should this use include_once instead?

Definition at line 905 of file Util.php.

References PEAR\raiseError().

Referenced by createTagFromArray(), and isValidName().

906  {
907  require_once 'PEAR.php';
908  return PEAR::raiseError($msg, $code);
909  }
& raiseError($message=null, $code=null, $mode=null, $options=null, $userinfo=null, $error_class=null, $skipmsg=false)
This method is a wrapper that returns an instance of the configured error class with this object&#39;s de...
Definition: PEAR.php:524
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ replaceEntities()

XML_Util::replaceEntities (   $string,
  $replaceEntities = XML_UTIL_ENTITIES_XML,
  $encoding = 'ISO-8859-1' 
)
static

replace XML entities

With the optional second parameter, you may select, which entities should be replaced.

require_once 'XML/Util.php';

// replace XML entites: $string = XML_Util::replaceEntities('This string contains < & >.');

With the optional third parameter, you may pass the character encoding require_once 'XML/Util.php';

// replace XML entites in UTF-8: $string = XML_Util::replaceEntities( 'This string contains < & > as well as ä, ö, ß, à and ê', XML_UTIL_ENTITIES_HTML, 'UTF-8' );

Parameters
string$stringstring where XML special chars should be replaced
int$replaceEntitiessetting for entities in attribute values (one of XML_UTIL_ENTITIES_XML, XML_UTIL_ENTITIES_XML_REQUIRED, XML_UTIL_ENTITIES_HTML)
string$encodingencoding value (if any)... must be a valid encoding as determined by the htmlentities() function
Returns
string string with replaced chars public
See also
reverseEntities()

Definition at line 179 of file Util.php.

References XML_UTIL_ENTITIES_HTML, XML_UTIL_ENTITIES_XML, and XML_UTIL_ENTITIES_XML_REQUIRED.

Referenced by attributesToString(), and createTagFromArray().

181  {
182  switch ($replaceEntities) {
184  return strtr($string, array(
185  '&' => '&amp;',
186  '>' => '&gt;',
187  '<' => '&lt;',
188  '"' => '&quot;',
189  '\'' => '&apos;' ));
190  break;
192  return strtr($string, array(
193  '&' => '&amp;',
194  '<' => '&lt;',
195  '"' => '&quot;' ));
196  break;
198  return htmlentities($string, ENT_COMPAT, $encoding);
199  break;
200  }
201  return $string;
202  }
const XML_UTIL_ENTITIES_XML_REQUIRED
replace only required XML entitites This setting will replace <, " and &
Definition: Util.php:95
const XML_UTIL_ENTITIES_HTML
replace HTML entitites http://www.php.net/htmlentities
Definition: Util.php:101
const XML_UTIL_ENTITIES_XML
replace all XML entitites This setting will replace <, >, ", &#39; and &
Definition: Util.php:89
+ Here is the caller graph for this function:

◆ reverseEntities()

XML_Util::reverseEntities (   $string,
  $replaceEntities = XML_UTIL_ENTITIES_XML,
  $encoding = 'ISO-8859-1' 
)
static

reverse XML entities

With the optional second parameter, you may select, which entities should be reversed.

require_once 'XML/Util.php';

// reverse XML entites: $string = XML_Util::reverseEntities('This string contains < & >.');

With the optional third parameter, you may pass the character encoding require_once 'XML/Util.php';

// reverse XML entites in UTF-8: $string = XML_Util::reverseEntities( 'This string contains < & > as well as' . ' ä, ö, ß, à and ê', XML_UTIL_ENTITIES_HTML, 'UTF-8' );

Parameters
string$stringstring where XML special chars should be replaced
int$replaceEntitiessetting for entities in attribute values (one of XML_UTIL_ENTITIES_XML, XML_UTIL_ENTITIES_XML_REQUIRED, XML_UTIL_ENTITIES_HTML)
string$encodingencoding value (if any)... must be a valid encoding as determined by the html_entity_decode() function
Returns
string string with replaced chars public
See also
replaceEntities()

Definition at line 245 of file Util.php.

References XML_UTIL_ENTITIES_HTML, XML_UTIL_ENTITIES_XML, and XML_UTIL_ENTITIES_XML_REQUIRED.

247  {
248  switch ($replaceEntities) {
250  return strtr($string, array(
251  '&amp;' => '&',
252  '&gt;' => '>',
253  '&lt;' => '<',
254  '&quot;' => '"',
255  '&apos;' => '\'' ));
256  break;
258  return strtr($string, array(
259  '&amp;' => '&',
260  '&lt;' => '<',
261  '&quot;' => '"' ));
262  break;
264  return html_entity_decode($string, ENT_COMPAT, $encoding);
265  break;
266  }
267  return $string;
268  }
const XML_UTIL_ENTITIES_XML_REQUIRED
replace only required XML entitites This setting will replace <, " and &
Definition: Util.php:95
const XML_UTIL_ENTITIES_HTML
replace HTML entitites http://www.php.net/htmlentities
Definition: Util.php:101
const XML_UTIL_ENTITIES_XML
replace all XML entitites This setting will replace <, >, ", &#39; and &
Definition: Util.php:89

◆ splitQualifiedName()

XML_Util::splitQualifiedName (   $qname,
  $defaultNs = null 
)
static

split qualified name and return namespace and local part

require_once 'XML/Util.php';

// split qualified tag $parts = XML_Util::splitQualifiedName('xslt:stylesheet'); the returned array will contain two elements:

array(
    'namespace' => 'xslt',
    'localPart' => 'stylesheet'
);
Parameters
string$qnamequalified tag name
string$defaultNsdefault namespace (optional)
Returns
array array containing namespace and local part public

Definition at line 829 of file Util.php.

Referenced by createStartElement(), and createTagFromArray().

830  {
831  if (strstr($qname, ':')) {
832  $tmp = explode(':', $qname);
833  return array(
834  'namespace' => $tmp[0],
835  'localPart' => $tmp[1]
836  );
837  }
838  return array(
839  'namespace' => $defaultNs,
840  'localPart' => $qname
841  );
842  }
+ Here is the caller graph for this function:

The documentation for this class was generated from the following file: