[ Index ]
 

Code source de phpMyVisites 2.3

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/libs/Xml/ -> Util.php (sommaire)

error code for invalid chars in XML name

Poids: 743 lignes (27 kb)
Inclus ou requis:0 fois
Référencé: 0 fois
Nécessite: 0 fichiers

Définit 1 class

XML_Util:: (16 méthodes):
  apiVersion()
  replaceEntities()
  reverseEntities()
  getXMLDeclaration()
  getDocTypeDeclaration()
  attributesToString()
  collapseEmptyTags()
  createTag()
  createTagFromArray()
  createStartElement()
  createEndElement()
  createComment()
  createCDataSection()
  splitQualifiedName()
  isValidName()
  raiseError()


Classe: XML_Util  - X-Ref

utility class for working with XML documents

apiVersion()   X-Ref
return API version

return: string  $version API version

replaceEntities($string, $replaceEntities = XML_UTIL_ENTITIES_XML)   X-Ref
replace XML entities

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

<code>
require_once 'XML/Util.php';

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

param: string  string where XML special chars should be replaced
param: integer setting for entities in attribute values (one of XML_UTIL_ENTITIES_XML, XML_UTIL_ENTITIES_XML_REQUIRED, XML_UTIL_ENTITIES_HTML)
return: string  string with replaced chars

reverseEntities($string, $replaceEntities = XML_UTIL_ENTITIES_XML)   X-Ref
reverse XML entities

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

<code>
require_once 'XML/Util.php';

// reverse XML entites:
$string = XML_Util::reverseEntities("This string contains &lt; &amp; &gt;.");
</code>

param: string  string where XML special chars should be replaced
param: integer setting for entities in attribute values (one of XML_UTIL_ENTITIES_XML, XML_UTIL_ENTITIES_XML_REQUIRED, XML_UTIL_ENTITIES_HTML)
return: string  string with replaced chars

getXMLDeclaration($version = "1.0", $encoding = null, $standalone = null)   X-Ref
build an xml declaration

<code>
require_once 'XML/Util.php';

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

param: string  $version     xml version
param: string  $encoding    character encoding
param: boolean $standAlone  document is standalone (or not)
return: string  $decl xml declaration

getDocTypeDeclaration($root, $uri = null, $internalDtd = null)   X-Ref
build a document type declaration

<code>
require_once 'XML/Util.php';

// get a doctype declaration:
$xmlDecl = XML_Util::getDocTypeDeclaration("rootTag","myDocType.dtd");
</code>

param: string  $root         name of the root tag
param: string  $uri          uri of the doctype definition (or array with uri and public id)
param: string  $internalDtd  internal dtd entries   
return: string  $decl         doctype declaration

attributesToString($attributes, $sort = true, $multiline = false, $indent = ' ', $linebreak = "\n", $entities = XML_UTIL_ENTITIES_XML)   X-Ref
create string representation of an attribute list

<code>
require_once 'XML/Util.php';

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

$attList = XML_Util::attributesToString($att);
</code>

param: array         $attributes        attribute array
param: boolean|array $sort              sort attribute list alphabetically, may also be an assoc array containing the keys 'sort', 'multiline', 'indent', 'linebreak' and 'entities'
param: boolean       $multiline         use linebreaks, if more than one attribute is given
param: string        $indent            string used for indentation of multiline attributes
param: string        $linebreak         string used for linebreaks of multiline attributes
param: integer       $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)
return: string                           string representation of the attributes

collapseEmptyTags($xml, $mode = XML_UTIL_COLLAPSE_ALL)   X-Ref
Collapses empty tags.

param: string  $xml  XML
param: integer $mode Whether to collapse all empty tags (XML_UTIL_COLLAPSE_ALL) or only XHTML (XML_UTIL_COLLAPSE_XHTML_ONLY) ones.
return: string  $xml  XML

createTag($qname, $attributes = array()   X-Ref
create a tag

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

<code>
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#");
</code>

param: string  $qname             qualified tagname (including namespace)
param: array   $attributes        array containg attributes
param: mixed   $content
param: string  $namespaceUri      URI of the namespace
param: integer $replaceEntities   whether to replace XML special chars in content, embedd it in a CData section or none of both
param: boolean $multiline         whether to create a multiline tag where each attribute gets written to a single line
param: string  $indent            string used to indent attributes (_auto indents attributes so they start at the same column)
param: string  $linebreak         string used for linebreaks
return: string  $string            XML tag

createTagFromArray($tag, $replaceEntities = XML_UTIL_REPLACE_ENTITIES, $multiline = false, $indent = "_auto", $linebreak = "\n" )   X-Ref
create a tag from an array
this method awaits an array in the following format
<pre>
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)
)
</pre>

<code>
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);
</code>

param: array   $tag               tag definition
param: integer $replaceEntities   whether to replace XML special chars in content, embedd it in a CData section or none of both
param: boolean $multiline         whether to create a multiline tag where each attribute gets written to a single line
param: string  $indent            string used to indent attributes (_auto indents attributes so they start at the same column)
param: string  $linebreak         string used for linebreaks
return: string  $string            XML tag

createStartElement($qname, $attributes = array()   X-Ref
create a start element

<code>
require_once 'XML/Util.php';

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

param: string  $qname             qualified tagname (including namespace)
param: array   $attributes        array containg attributes
param: string  $namespaceUri      URI of the namespace
param: boolean $multiline         whether to create a multiline tag where each attribute gets written to a single line
param: string  $indent            string used to indent attributes (_auto indents attributes so they start at the same column)
param: string  $linebreak         string used for linebreaks
return: string  $string            XML start element

createEndElement($qname)   X-Ref
create an end element

<code>
require_once 'XML/Util.php';

// create an XML start element:
$tag = XML_Util::createEndElement("myNs:myTag");
</code>

param: string  $qname             qualified tagname (including namespace)
return: string  $string            XML end element

createComment($content)   X-Ref
create an XML comment

<code>
require_once 'XML/Util.php';

// create an XML start element:
$tag = XML_Util::createComment("I am a comment");
</code>

param: string  $content           content of the comment
return: string  $comment           XML comment

createCDataSection($data)   X-Ref
create a CData section

<code>
require_once 'XML/Util.php';

// create a CData section
$tag = XML_Util::createCDataSection("I am content.");
</code>

param: string  $data              data of the CData section
return: string  $string            CData section with content

splitQualifiedName($qname, $defaultNs = null)   X-Ref
split qualified name and return namespace and local part

<code>
require_once 'XML/Util.php';

// split qualified tag
$parts = XML_Util::splitQualifiedName("xslt:stylesheet");
</code>
the returned array will contain two elements:
<pre>
array(
"namespace" => "xslt",
"localPart" => "stylesheet"
);
</pre>

param: string    $qname      qualified tag name
param: string    $defaultNs  default namespace (optional)
return: array     $parts      array containing namespace and local part

isValidName($string)   X-Ref
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>

<code>
require_once 'XML/Util.php';

// verify tag name
$result = XML_Util::isValidName("invalidTag?");
if (XML_Util::isError($result)) {
print "Invalid XML name: " . $result->getMessage();
}
</code>

param: string  $string string that should be checked
return: mixed   $valid  true, if string is a valid XML name, PEAR error otherwise

raiseError($msg, $code)   X-Ref
replacement for XML_Util::raiseError

Avoids the necessity to always require
PEAR.php

param: string      error message
param: integer     error code
return: object PEAR_Error



Généré le : Mon Nov 26 14:10:01 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics