Source for file Beautifier.php
Documentation is available at Beautifier.php
* Format XML files containing unknown entities (like all of peardoc)
* phpDocumentor :: automatic documentation generator
* Copyright (c) 2004-2006 Gregory Beaver
* This library is free software; you can redistribute it
* and/or modify it under the terms of the GNU Lesser General
* Public License as published by the Free Software Foundation;
* either version 2.1 of the License, or (at your option) any
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* @copyright 2004-2006 Gregory Beaver
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @version CVS: $Id: Beautifier.php 212211 2006-04-30 22:18:14Z cellog $
* @link http://www.phpdoc.org
* @link http://pear.php.net/PhpDocumentor
* This is just like XML_Beautifier, but uses {@link phpDocumentor_XML_Beautifier_Tokenizer}
* @param string $file filename
* @param mixed $newFile filename for beautified XML file (if none is given, the XML string will be returned.)
* if you want overwrite the original file, use XML_BEAUTIFIER_OVERWRITE
* @param string $renderer Renderer to use, default is the plain xml renderer
* @return mixed XML string of no file should be written, true if file could be written
* @uses _loadRenderer() to load the desired renderer
function formatFile($file, $newFile = null, $renderer = "Plain")
if ($this->apiVersion() != '1.0') {
return $this->raiseError('API version must be 1.0');
* Split the document into tokens
* using the XML_Tokenizer
require_once dirname(__FILE__ ) . '/Tokenizer.php';
$tokens = $tokenizer->tokenize( $file, true );
if (PEAR::isError($tokens)) {
include_once dirname(__FILE__ ) . '/Plain.php';
$renderer = new PHPDoc_XML_Beautifier_Renderer_Plain($this->_options);
$xml = $renderer->serialize($tokens);
$fp = @fopen($newFile, "w");
return PEAR::raiseError("Could not write to output file", XML_BEAUTIFIER_ERROR_NO_OUTPUT_FILE);
* @param string $string XML
* @return string formatted XML string
if ($this->apiVersion() != '1.0') {
return $this->raiseError('API version must be 1.0');
* Split the document into tokens
* using the XML_Tokenizer
require_once dirname(__FILE__ ) . '/Tokenizer.php';
$tokens = $tokenizer->tokenize( $string, false );
if (PEAR::isError($tokens)) {
include_once dirname(__FILE__ ) . '/Plain.php';
$renderer = new PHPDoc_XML_Beautifier_Renderer_Plain($this->_options);
$xml = $renderer->serialize($tokens);
|