Class XmlRender

Description

Creates and renders a XML tree based on PHP values

The XmlRender is able to convert PHP values (strings, numbers, arrays, objects) to XML nodes. Finally, the generated XML tree can be transformed into a XML string.

Example:

  1.  $renderer new XmlRender('root'array('attrib' => 'value'));
  2.  $renderer->setCharset('iso-8859-1');
  3.  $renderer->Document->setDoctype('SYSTEM''file.dtd');
  4.  $root =$renderer->getRoot();
  5.  $root->addChild(new XmlNode('child'array('attrib' => 'value')));
  6.  $renderer->render('iso-8859-1');
  7.  $renderer->download('file_name.xml');

Located in /core/xml/XmlRender.class.php (line 58)

PHP2Go
   |
   --XmlRender
Variable Summary
Method Summary
XmlRender XmlRender (string $rootTag, [array $rootAttrs = array()])
void addContent (mixed $value, [array $options = array()])
void addContentAt (XmlNode &$Node, mixed $value, [array $options = array()])
void addDataSet (DataSet $DataSet, [array $options = array()])
void download (string $fileName, [bool $showHeaders = TRUE], [string $mimeType = 'text/xml'])
string getContent ()
void render ([string $lineEnd = ''], [string $indent = ''])
void setAddOptions (array $options, [bool $overwrite = FALSE])
void setCharset (string $charset)
bool toFile (string $fileName)
void _addArray (XmlNode &$Node, array $array, [array $options = array()])
void _addObject (XmlNode &$Node, object $Object, [array $options = array()])
void _addValue (XmlNode &$Node, mixed $value, [array $options = array()])
Variables
array $addOptions = array() (line 82)

Rendering options

Indicates how objects, arrays and other PHP native types should be converted into XML nodes.

string $charset (line 65)

XML document's charset

string $content = '' (line 72)

XML contents

XmlDocument $Document = NULL (line 89)

XML document

Methods
Constructor XmlRender (line 98)

Builds the root node of the XML tree

XmlRender XmlRender (string $rootTag, [array $rootAttrs = array()])
  • string $rootTag: Root tag name
  • array $rootAttrs: Root attributes
addContent (line 153)

Generic method to add content in the XML tree

Content will be added under the tree's root node

void addContent (mixed $value, [array $options = array()])
  • mixed $value: Content to be added
  • array $options: Add options
addContentAt (line 164)

Generic method to add content under a given node

void addContentAt (XmlNode &$Node, mixed $value, [array $options = array()])
  • XmlNode &$Node: Insert point
  • mixed $value: Content to be added
  • array $options: Add options
addDataSet (line 190)

Adds a data set in the XML tree

The data set is added under the tree's root node.

  1.  $xml new XmlRender('rows');
  2.  $xml->setAddOptions(array('defaultNodeName'=>'row'));
  3.  $dataset =DataSet::factory('db');
  4.  $dataset->load('select * from my_table');
  5.  $xml->addDataSet($dataset);
  6.  $xml->toFile('my_table.xml');

void addDataSet (DataSet $DataSet, [array $options = array()])
  • DataSet $DataSet: Loaded data set
  • array $options: Add options
download (line 230)

Displays the generated XML string, along with the download HTTP headers

void download (string $fileName, [bool $showHeaders = TRUE], [string $mimeType = 'text/xml'])
  • string $fileName: File name
  • bool $showHeaders: If set to FALSE, HTTP download headers will be supressed
  • string $mimeType: Alternate MIME type
getContent (line 219)

Returns the generated XML string

You must call render() before calling getContent(), download() or toFile().

string getContent ()
getRoot (line 110)

Get the tree's root node

XmlNode &getRoot ()
render (line 206)

Renders the XML string

void render ([string $lineEnd = ''], [string $indent = ''])
  • string $lineEnd: Line end chars
  • string $indent: Indentation chars
setAddOptions (line 139)

Set default rendering options

These options will be used when add methods are called. The list of available options are:

  • defaultNodeName: default name for XML nodes
  • typeHints: add type hints when rendering nodes
  • classAsNodeName: define the class name as node name, when adding objects
  • createArrayNode: must create a node representing the array itself (not only its members)
  • arrayEntryAsRepeat: create a sequence of nodes of the same name when the value of a hash key is a numeric array
  • attributeKey: array key that contains the attributes of a node
  • cdataKey: array key that contains the CDATA section of a node

void setAddOptions (array $options, [bool $overwrite = FALSE])
  • array $options: Options
  • bool $overwrite: Override existent options
setCharset (line 119)

Set the document's charset

void setCharset (string $charset)
  • string $charset: Charset
toFile (line 246)

Saves the XML string on a file

bool toFile (string $fileName)
  • string $fileName: File path
_addArray (line 287)

Internal method used to add an array in the XML tree

  • access: private
void _addArray (XmlNode &$Node, array $array, [array $options = array()])
  • XmlNode &$Node: Insert point
  • array $array: Array to be added
  • array $options: Add options
_addObject (line 269)

Internal method used to add an object in the XML tree

  • access: private
void _addObject (XmlNode &$Node, object $Object, [array $options = array()])
  • XmlNode &$Node: Insert point
  • object $Object: Object to be added
  • array $options: Add options
_addValue (line 359)

Internal method to add a string, boolean or numeric value in the XML tree

void _addValue (XmlNode &$Node, mixed $value, [array $options = array()])
  • XmlNode &$Node: Insert point
  • mixed $value: Value to be added
  • array $options: Add options

Inherited Methods

Inherited From PHP2Go

PHP2Go::PHP2Go()
PHP2Go::equals()
PHP2Go::generateUniqueId()
PHP2Go::getClassName()
PHP2Go::getConfigVal()
PHP2Go::getLangVal()
PHP2Go::getObjectName()
PHP2Go::getParentName()
PHP2Go::hasDestructor()
PHP2Go::hashCode()
PHP2Go::isA()
PHP2Go::isSubclassOf()
PHP2Go::logError()
PHP2Go::raiseError()
PHP2Go::registerDestructor()
PHP2Go::registerShutdownFunc()
PHP2Go::retrieve()
PHP2Go::store()
PHP2Go::__toString()

Documentation generated on Sun, 07 Oct 2007 19:31:19 -0300 by phpDocumentor 1.3.2