PEAR
[ class tree: PEAR ] [ index: PEAR ] [ all elements ]

Class: PEAR_PackageFile_Generator_v2_XML_Util

Source Location: /PEAR-1.7.2/PEAR/PackageFile/Generator/v2.php

Class Overview


utility class for working with XML documents


Author(s):

Version:

  • 0.6.0

Methods


Inherited Variables

Inherited Methods


Class Details

[line 950]
utility class for working with XML documents

customized version of XML_Util 0.6.0



[ Top ]


Method Detail

apiVersion   [line 959]

string apiVersion( )

return API version
  • Return: API version
  • Access: public

[ Top ]

attributesToString   [line 1112]

string attributesToString( array $attributes, [boolean|array $sort = true], [boolean $multiline = false], [string $indent = ' '], [string $linebreak = "\n"], [integer $entities = PEAR_PackageFile_Generator_v2_XML_Util_ENTITIES_XML])

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.  


Parameters:

array   $attributes   —  attribute array
boolean|array   $sort   —  sort attribute list alphabetically, may also be an assoc array containing the keys 'sort', 'multiline', 'indent', 'linebreak' and 'entities'
boolean   $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
integer   $entities   —  setting for entities in attribute values (one of PEAR_PackageFile_Generator_v2_XML_Util_ENTITIES_NONE, PEAR_PackageFile_Generator_v2_XML_Util_ENTITIES_XML, PEAR_PackageFile_Generator_v2_XML_Util_ENTITIES_XML_REQUIRED, PEAR_PackageFile_Generator_v2_XML_Util_ENTITIES_HTML)

[ Top ]

createCDataSection   [line 1430]

string createCDataSection( string $data)

create a CData section

  1.  require_once 'XML/Util.php';
  2.  
  3.  // create a CData section

  • Return: CData section with content
  • Access: public

Parameters:

string   $data   —  data of the CData section

[ Top ]

createComment   [line 1409]

string createComment( string $content)

create an XML comment

  1.  require_once 'XML/Util.php';
  2.  
  3.  // create an XML start element:
  4.  $tag PEAR_PackageFile_Generator_v2_XML_Util::createComment("I am a comment");

  • Return: XML comment
  • Access: public

Parameters:

string   $content   —  content of the comment

[ Top ]

createEndElement   [line 1388]

string createEndElement( string $qname)

create an end element

  1.  require_once 'XML/Util.php';
  2.  
  3.  // create an XML start element:


Parameters:

string   $qname   —  qualified tagname (including namespace)

[ Top ]

createStartElement   [line 1338]

string createStartElement( string $qname, [array $attributes = array()], [string $namespaceUri = null], [boolean $multiline = false], [string $indent = '_auto'], [string $linebreak = "\n"])

create a start element

  1.  require_once 'XML/Util.php';
  2.  
  3.  // create an XML start element:
  4.  $tag PEAR_PackageFile_Generator_v2_XML_Util::createStartElement("myNs:myTag"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
boolean   $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

[ Top ]

createTag   [line 1194]

string createTag( string $qname, [array $attributes = array()], [mixed $content = null], [string $namespaceUri = null], [integer $replaceEntities = PEAR_PackageFile_Generator_v2_XML_Util_REPLACE_ENTITIES], [boolean $multiline = false], [string $indent = "_auto"], [string $linebreak = "\n"], [string $encoding = PEAR_PackageFile_Generator_v2_XML_Util_ENTITIES_XML])

create a tag

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

  1.  require_once 'XML/Util.php';
  2.  
  3.  // create an XML tag:
  4.  $tag PEAR_PackageFile_Generator_v2_XML_Util::createTag("myNs:myTag"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   — 
string   $namespaceUri   —  URI of the namespace
integer   $replaceEntities   —  whether to replace XML special chars in content, embedd it in a CData section or none of both
boolean   $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
string   $encoding   —  encoding that should be used to translate content

[ Top ]

createTagFromArray   [line 1253]

string createTagFromArray( array $tag, [integer $replaceEntities = PEAR_PackageFile_Generator_v2_XML_Util_REPLACE_ENTITIES], [boolean $multiline = false], [string $indent = "_auto"], [string $linebreak = "\n"], [ $encoding = PEAR_PackageFile_Generator_v2_XML_Util_ENTITIES_XML])

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


Parameters:

array   $tag   —  tag definition
integer   $replaceEntities   —  whether to replace XML special chars in content, embedd it in a CData section or none of both
boolean   $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
   $encoding   — 

[ Top ]

getDocTypeDeclaration   [line 1068]

string getDocTypeDeclaration( string $root, [string $uri = null], [string $internalDtd = null])

build a document type declaration

  1.  require_once 'XML/Util.php';
  2.  
  3.  // get a doctype declaration:
  4.  $xmlDecl PEAR_PackageFile_Generator_v2_XML_Util::getDocTypeDeclaration("rootTag","myDocType.dtd");

  • 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

[ Top ]

getXMLDeclaration   [line 1033]

string getXMLDeclaration( [string $version = "1.0"], [string $encoding = null], [ $standalone = null], boolean $standAlone)

build an xml declaration

  1.  require_once 'XML/Util.php';
  2.  
  3.  // get an XML declaration:
  4.  $xmlDecl PEAR_PackageFile_Generator_v2_XML_Util::getXMLDeclaration("1.0""UTF-8"true);


Parameters:

string   $version   —  xml version
string   $encoding   —  character encoding
boolean   $standAlone   —  document is standalone (or not)
   $standalone   — 

[ Top ]

isValidName   [line 1499]

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.

  1.  require_once 'XML/Util.php';
  2.  
  3.  // verify tag name
  4.  if (PEAR_PackageFile_Generator_v2_XML_Util::isError($result)) {
  5.     print "Invalid XML name: " $result->getMessage();
  6.  }

  • Return: true, if string is a valid XML name, PEAR error otherwise
  • Todo: support for other charsets
  • Access: public

Parameters:

string   $string   —  string that should be checked

[ Top ]

raiseError   [line 1525]

object PEAR_Error raiseError( string $msg, integer $code)

replacement for PEAR_PackageFile_Generator_v2_XML_Util::raiseError

Avoids the necessity to always require PEAR.php

  • Access: public

Parameters:

string   $msg   —  error message
integer   $code   —  error code

[ Top ]

replaceEntities   [line 983]

string replaceEntities( string $string, [integer $replaceEntities = PEAR_PackageFile_Generator_v2_XML_Util_ENTITIES_XML])

replace XML entities

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

  1.  require_once 'XML/Util.php';
  2.  
  3.  // replace XML entites:
  4.  $string PEAR_PackageFile_Generator_v2_XML_Util::replaceEntities("This string contains < & >.");


Parameters:

string   $string   —  string where XML special chars should be replaced
integer   $replaceEntities   —  setting for entities in attribute values (one of PEAR_PackageFile_Generator_v2_XML_Util_ENTITIES_XML, PEAR_PackageFile_Generator_v2_XML_Util_ENTITIES_XML_REQUIRED, PEAR_PackageFile_Generator_v2_XML_Util_ENTITIES_HTML)

[ Top ]

splitQualifiedName   [line 1458]

array splitQualifiedName( string $qname, [string $defaultNs = null])

split qualified name and return namespace and local part

  1.  require_once 'XML/Util.php';
  2.  
  3.  // split qualified tag
the returned array will contain two elements:
 array(
       "namespace" => "xslt",
       "localPart" => "stylesheet"
      );


Parameters:

string   $qname   —  qualified tag name
string   $defaultNs   —  default namespace (optional)

[ Top ]


Documentation generated on Mon, 11 Mar 2019 15:21:51 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.