utility class for working with XML documents
Located in Program_Root/XML_Util.php (line 48)
PEAR | --XML_Util
return API version
create string representation of an attribute list
1 require_once 'XML/Util.php';
2
3 // build an attribute string
4 $att = array(
5 "foo" => "bar",
6 "argh" => "tomato"
7 );
8
9 $attList = XML_Util::attributesToString($att);
create a tag
This method will call XML_Util::createTagFromArray(), which is more flexible.
1 require_once 'XML/Util.php';
2
3 // create an XML tag:
4 $tag = XML_Util::createTag("myNs:myTag", array("foo" => "bar"), "This is inside the tag", "http://www.w3c.org/myNs#");
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) )
1 require_once 'XML/Util.php';
2
3 $tag = array(
4 "qname" => "foo:bar",
5 "namespaceUri" => "http://foo.com",
6 "attributes" => array( "key" => "value", "argh" => "fruit&vegetable" ),
7 "content" => "I'm inside the tag"
8 );
9 // creating a tag with qualified name and namespaceUri
10 $string = XML_Util::createTagFromArray($tag);
build an xml declaration
1 require_once 'XML/Util.php';
2
3 // get an XML declaration:
4 $xmlDecl = XML_Util::getXMLDeclaration("1.0", "UTF-8", true
check, whether string is valid XML name
<p>XML names are used for tagname, attribute names and various other, lesser known entities.</p> <p>An XML name may only consist of alphanumeric characters, dashes, undescores and periods, and has to start with a letter or an underscore. </p>
1 require_once 'XML/Util.php';
2
3 // verify tag name
4 $result = XML_Util::isValidName("invalidTag?");
5 if (XML_Util::isError($result)) {
6 print "Invalid XML name: " . $result->getMessage();
7 }
replace XML entities
chars that have to be replaced are '&' and '<', furthermore '>', ''' and '"' have entities that can be used.
1 require_once 'XML/Util.php';
2
3 // replace XML entites:
4 $string = XML_Util::replaceEntities("This string contains < & >.");
split qualified name and return namespace and local part
the returned array will contain two elements:
1 require_once 'XML/Util.php';
2
3 // split qualified tag
4 $parts = XML_Util::splitQualifiedName("xslt:stylesheet");
array( "namespace" => "xslt", "localPart" => "stylesheet" );
Documention generated on Fri, 1 Aug 2003 17:12:19 +0200 by phpDocumentor 1.2.1