apiVersion [line 133]
Return API version
- Return: API version
- Access: public
attributesToString [line 392]
string attributesToString(
array
$attributes, [bool|array
$sort = true], [bool
$multiline = false], [string
$indent = ' '], [string
$linebreak = "\n"], [int
$entities = XML_UTIL_ENTITIES_XML])
Create string representation of an attribute list
require_once 'XML/Util.php';
// build an attribute string
$att = array(
'foo' => 'bar',
'argh' => 'tomato'
);
Parameters:
array
$attributes
—
attribute array
bool|array
$sort
—
sort attribute list alphabetically, may also be an assoc array containing the keys 'sort', 'multiline', 'indent', 'linebreak' and 'entities'
bool
$multiline
—
use linebreaks, if more than one attribute is given
string
$indent
—
string used for indentation of multiline attributes
string
$linebreak
—
string used for linebreaks of multiline attributes
int
$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)
collapseEmptyTags [line 460]
string collapseEmptyTags(
string
$xml, [int
$mode = XML_UTIL_COLLAPSE_ALL])
Collapses empty tags.
Parameters:
string
$xml
—
XML
int
$mode
—
Whether to collapse all empty tags (XML_UTIL_COLLAPSE_ALL) or only XHTML (XML_UTIL_COLLAPSE_XHTML_ONLY) ones.
createCDataSection [line 847]
string createCDataSection(
string
$data)
Create a CData section
require_once 'XML/Util.php';
// create a CData section
Parameters:
string
$data
—
data of the CData section
createComment [line 827]
string createComment(
string
$content)
Create an XML comment
require_once 'XML/Util.php';
// create an XML start element:
- Return: XML comment
- Access: public
Parameters:
string
$content
—
content of the comment
createEndElement [line 807]
string createEndElement(
string
$qname)
Create an end element
require_once 'XML/Util.php';
// create an XML start element:
Parameters:
string
$qname
—
qualified tagname (including namespace)
createStartElement [line 752]
string createStartElement(
string
$qname, [array
$attributes = array()], [string
$namespaceUri = null], [bool
$multiline = false], [string
$indent = '_auto'], [string
$linebreak = "\n"], [bool
$sortAttributes = true])
Create a start element
require_once 'XML/Util.php';
// create an XML start element:
array('foo' => 'bar') ,'http://www.w3c.org/myNs#');
Parameters:
string
$qname
—
qualified tagname (including namespace)
array
$attributes
—
array containg attributes
string
$namespaceUri
—
URI of the namespace
bool
$multiline
—
whether to create a multiline tag where each attribute gets written to a single line
string
$indent
—
string used to indent attributes (_auto indents attributes so they start at the same column)
string
$linebreak
—
string used for linebreaks
bool
$sortAttributes
—
Whether to sort the attributes or not
createTag [line 541]
string createTag(
string
$qname, [array
$attributes = array()], [mixed
$content = null], [string
$namespaceUri = null], [int
$replaceEntities = XML_UTIL_REPLACE_ENTITIES], [bool
$multiline = false], [string
$indent = '_auto'], [string
$linebreak = "\n"], [bool
$sortAttributes = true], [int
$collapseTagMode = XML_UTIL_COLLAPSE_ALL])
Create a tag
This method will call XML_Util::createTagFromArray(), which is more flexible.
require_once 'XML/Util.php';
// create an XML tag:
array('foo' => 'bar'),
'This is inside the tag',
'http://www.w3c.org/myNs#');
Parameters:
string
$qname
—
qualified tagname (including namespace)
array
$attributes
—
array containg attributes
mixed
$content
—
the content
string
$namespaceUri
—
URI of the namespace
int
$replaceEntities
—
whether to replace XML special chars in content, embedd it in a CData section or none of both
bool
$multiline
—
whether to create a multiline tag where each attribute gets written to a single line
string
$indent
—
string used to indent attributes (_auto indents attributes so they start at the same column)
string
$linebreak
—
string used for linebreaks
bool
$sortAttributes
—
Whether to sort the attributes or not
int
$collapseTagMode
—
How to handle a content-less, and thus collapseable, tag
createTagFromArray [line 629]
string createTagFromArray(
array
$tag, [int
$replaceEntities = XML_UTIL_REPLACE_ENTITIES], [bool
$multiline = false], [string
$indent = '_auto'], [string
$linebreak = "\n"], [bool
$sortAttributes = true], [int
$collapseTagMode = XML_UTIL_COLLAPSE_ALL])
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
Parameters:
array
$tag
—
tag definition
int
$replaceEntities
—
whether to replace XML special chars in content, embedd it in a CData section or none of both
bool
$multiline
—
whether to create a multiline tag where each attribute gets written to a single line
string
$indent
—
string used to indent attributes (_auto indents attributes so they start at the same column)
string
$linebreak
—
string used for linebreaks
bool
$sortAttributes
—
Whether to sort the attributes or not
int
$collapseTagMode
—
How to handle a content-less, and thus collapseable, tag
getDocTypeDeclaration [line 338]
string getDocTypeDeclaration(
string
$root, [string
$uri = null], [string
$internalDtd = null])
Build a document type declaration
require_once 'XML/Util.php';
// get a doctype declaration:
- Return: doctype declaration
- Since: 0.2
- Access: public
Parameters:
string
$root
—
name of the root tag
string
$uri
—
uri of the doctype definition (or array with uri and public id)
string
$internalDtd
—
internal dtd entries
getXMLDeclaration [line 299]
string getXMLDeclaration(
[string
$version = '1.0'], [string
$encoding = null], [bool
$standalone = null])
Build an xml declaration
require_once 'XML/Util.php';
// get an XML declaration:
Parameters:
string
$version
—
xml version
string
$encoding
—
character encoding
bool
$standalone
—
document is standalone (or not)
isValidName [line 918]
mixed isValidName(
string
$string)
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
if
(is_a ($result, 'PEAR_Error')) {
print 'Invalid XML name: ' . $result->getMessage();
}
- Return: true, if string is a valid XML name, PEAR error otherwise
- Todo: PEAR CS - unable to avoid 85-char limit on second preg_match
- Todo: support for other charsets
- Access: public
Parameters:
string
$string
—
string that should be checked
raiseError [line 957]
PEAR_Error raiseError(
string
$msg, int
$code)
Replacement for XML_Util::raiseError
Avoids the necessity to always require PEAR.php
Parameters:
string
$msg
—
error message
int
$code
—
error code
replaceEntities [line 176]
string replaceEntities(
string
$string, [int
$replaceEntities = XML_UTIL_ENTITIES_XML], [string
$encoding = 'ISO-8859-1'])
Replace XML entities
With the optional second parameter, you may select, which entities should be replaced.
require_once 'XML/Util.php';
// replace XML entites:
With the optional third parameter, you may pass the character encoding require_once 'XML/Util.php';
// replace XML entites in UTF-8:
'This string contains < & > as well as ä, ö, ß, à and ê',
'UTF-8'
);
Parameters:
string
$string
—
string where XML special chars should be replaced
int
$replaceEntities
—
setting for entities in attribute values (one of XML_UTIL_ENTITIES_XML, XML_UTIL_ENTITIES_XML_REQUIRED, XML_UTIL_ENTITIES_HTML)
string
$encoding
—
encoding value (if any)... must be a valid encoding as determined by the htmlentities() function
reverseEntities [line 248]
string reverseEntities(
string
$string, [int
$replaceEntities = XML_UTIL_ENTITIES_XML], [string
$encoding = 'ISO-8859-1'])
Reverse XML entities
With the optional second parameter, you may select, which entities should be reversed.
require_once 'XML/Util.php';
// reverse XML entites:
With the optional third parameter, you may pass the character encoding require_once 'XML/Util.php';
// reverse XML entites in UTF-8:
'This string contains < & > as well as'
. ' ä, ö, ß, à and ê',
'UTF-8'
);
Parameters:
string
$string
—
string where XML special chars should be replaced
int
$replaceEntities
—
setting for entities in attribute values (one of XML_UTIL_ENTITIES_XML, XML_UTIL_ENTITIES_XML_REQUIRED, XML_UTIL_ENTITIES_HTML)
string
$encoding
—
encoding value (if any)... must be a valid encoding as determined by the html_entity_decode() function
splitQualifiedName [line 877]
array splitQualifiedName(
string
$qname, [string
$defaultNs = null])
Split qualified name and return namespace and local part
require_once 'XML/Util.php';
// split qualified tag
the returned array will contain two elements:
array(
'namespace' => 'xslt',
'localPart' => 'stylesheet'
);
- Return: array containing namespace and local part
- Access: public
- Usedby: XML_Util::createTagFromArray() - to get local part and namespace of a qualified name
Parameters:
string
$qname
—
qualified tag name
string
$defaultNs
—
default namespace (optional)