Source for file Plain.php
Documentation is available at Plain.php
/* vim: set expandtab tabstop=4 shiftwidth=4: */
// +----------------------------------------------------------------------+
// +----------------------------------------------------------------------+
// | Copyright (c) 1997-2002 The PHP Group |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.0 of the PHP license, |
// | that is bundled with this package in the file LICENSE, and is |
// | available at through the world-wide-web at |
// | http://www.php.net/license/2_02.txt. |
// | If you did not receive a copy of the PHP license and are unable to |
// | obtain it through the world-wide-web, please send a note to |
// +----------------------------------------------------------------------+
// +----------------------------------------------------------------------+
* XML/Beautifier/Renderer/Plain.php
* @package XML_Beautifier
* XML_Util is needed to create the tags
require_once 'XML/Util.php';
require_once 'XML/Beautifier/Renderer.php';
* Basic XML Renderer for XML Beautifier
* @package XML_Beautifier
* @todo option to specify inline tags
* @todo option to specify treatment of whitespac in data sections
* @todo automatically create <![CDATA[ ]]> sections
* Serialize the XML tokens
* @param array XML tokens
* @return string XML document
$tokens = $this->normalize($tokens);
for($i = 0; $i < $cnt; $i++ )
$xml .= $this->_serializeToken($tokens[$i]);
* This method does the actual beautifying.
* @param array $token structure that should be serialized
* @todo split this method into smaller methods
function _serializeToken($token)
switch ($token["type"]) {
case XML_BEAUTIFIER_ELEMENT:
$indent = $this->_getIndentString($token["depth"]);
if ($this->_options["caseFolding"] === true) {
switch ($this->_options["caseFoldingTo"]) {
$token["tagname"] = strtoupper($token["tagname"]);
$token["tagname"] = strtolower($token["tagname"]);
if ($this->_options["multilineTags"] == true) {
switch ($token["contains"]) {
// contains only CData or is empty
case XML_BEAUTIFIER_CDATA:
case XML_BEAUTIFIER_EMPTY:
if (sizeof($token["children"]) >= 1) {
$data = $token["children"][0]["data"];
$data = "\n" . $this->_indentTextBlock( $data, $token['depth']+ 1, true );
$xml = $indent . XML_Util::createTag($token["tagname"], $token["attribs"], $data, null, false, $this->_options["multilineTags"], $attIndent)
. $this->_options["linebreak"];
// contains mixed content
$xml = $indent . XML_Util::createStartElement($token["tagname"], $token["attribs"], null, $this->_options["multilineTags"], $attIndent)
. $this->_options["linebreak"];
$cnt = count($token["children"]);
for ($i = 0; $i < $cnt; $i++ ) {
$xml .= $this->_serializeToken($token["children"][$i]);
$xml .= $indent . XML_Util::createEndElement($token["tagname"])
. $this->_options["linebreak"];
$xml = $token['data'] . $this->_options['linebreak'];
case XML_BEAUTIFIER_CDATA:
if ($token["depth"] > 0) {
$xml = str_repeat($this->_options["indent"], $token["depth"]);
$xml .= $token["data"] . $this->_options["linebreak"];
* serialize Processing instruction
$indent = $this->_getIndentString($token["depth"]);
$xml = $indent. "<?". $token["target"]. $this->_options["linebreak"]
. $this->_indentTextBlock(rtrim($token["data"]), $token["depth"])
. $indent. "?>". $this->_options["linebreak"];
case XML_BEAUTIFIER_COMMENT:
* normalize comment, i.e. combine it to one
* line and remove whitespace
if ($this->_options["normalizeComments"] && $lines > 1){
$comment = $token["data"];
* check for the maximum length of one line
if ($this->_options["maxCommentLine"] > 0) {
$commentLines = explode("\n", $comment);
$commentLines = array($comment);
for ($i = 0; $i < $lines; $i++ ) {
if (strlen($commentLines[$i]) <= $this->_options["maxCommentLine"]) {
$comment .= $commentLines[$i];
$comment .= wordwrap($commentLines[$i], $this->_options["maxCommentLine"] );
$indent = $this->_getIndentString($token["depth"]);
$xml = $indent . "<!--" . $this->_options["linebreak"]
. $this->_indentTextBlock($comment, $token["depth"]+ 1, true)
. $indent . "-->" . $this->_options["linebreak"];
$xml = $indent . sprintf( "<!-- %s -->", trim($comment) ) . $this->_options["linebreak"];
case XML_BEAUTIFIER_XML_DECLARATION:
$indent = $this->_getIndentString($token["depth"]);
$xml = $indent . XML_Util::getXMLDeclaration($token["version"], $token["encoding"], $token["standalone"]);
case XML_BEAUTIFIER_DT_DECLARATION:
case XML_BEAUTIFIER_DEFAULT:
$xml = XML_Util::replaceEntities( $token["data"] );
|