XML_Utilutility class for working with XML documents
Located in /PEAR/XML/Util.php (line 92)
string
attributesToString
(array $attributes, [boolean|array $sort = true], [boolean $multiline = false], [string $indent = ' '], [string $linebreak = "\n"], [integer $entities = XML_UTIL_ENTITIES_XML])
string
createStartElement
(string $qname, [array $attributes = array()], [string $namespaceUri = null], [boolean $multiline = false], [string $indent = '_auto'], [string $linebreak = "\n"])
string
createTag
(string $qname, [array $attributes = array()], [mixed $content = null], [string $namespaceUri = null], [integer $replaceEntities = XML_UTIL_REPLACE_ENTITIES], [boolean $multiline = false], [string $indent = "_auto"], [string $linebreak = "\n"])
string
createTagFromArray
(array $tag, [integer $replaceEntities = XML_UTIL_REPLACE_ENTITIES], [boolean $multiline = false], [string $indent = "_auto"], [string $linebreak = "\n"])
string
getXMLDeclaration
([string $version = "1.0"], [string $encoding = null], [mixed $standalone = null], boolean $standAlone)
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);
Collapses empty tags.
create a CData section
- require_once 'XML/Util.php';
- // create a CData section
- $tag = XML_Util::createCDataSection("I am content.");
create an XML comment
- require_once 'XML/Util.php';
- // create an XML start element:
- $tag = XML_Util::createComment("I am a comment");
create an end element
- require_once 'XML/Util.php';
- // create an XML start element:
- $tag = XML_Util::createEndElement("myNs:myTag");
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#");
create a tag
This method will call XML_Util::createTagFromArray(), which is more flexible.
create a tag from an array
this method awaits an array in the following format
array( "qname" => $qname // qualified name of the tag "namespace" => $namespace // namespace prefix (optional, if qname is specified or no namespace) "localpart" => $localpart, // local part of the tagname (optional, if qname is specified) "attributes" => array(), // array containing all attributes (optional) "content" => $content, // tag content (optional) "namespaceUri" => $namespaceUri // namespaceUri for the given namespace (optional) )
- 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);
build a document type declaration
- require_once 'XML/Util.php';
- // get a doctype declaration:
- $xmlDecl = XML_Util::getDocTypeDeclaration("rootTag","myDocType.dtd");
build an xml declaration
- require_once 'XML/Util.php';
- // get an XML declaration:
- $xmlDecl = XML_Util::getXMLDeclaration("1.0", "UTF-8", true);
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 (XML_Util::isError($result)) {
- print "Invalid XML name: " . $result->getMessage();
- }
replacement for XML_Util::raiseError
Avoids the necessity to always require PEAR.php
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 < & >.");
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 < & >.");
split qualified name and return namespace and local part
the returned array will contain two elements:
- require_once 'XML/Util.php';
- // split qualified tag
- $parts = XML_Util::splitQualifiedName("xslt:stylesheet");
array(
"namespace" => "xslt",
"localPart" => "stylesheet"
);
Documentation generated on Mon, 04 Dec 2006 11:10:20 -0500 by phpDocumentor 1.3.0RC3