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

Class: XML_Beautifier

Source Location: /XML_Beautifier-1.2.2/Beautifier.php

Class Overview


XML_Beautifier is a class that adds linebreaks and indentation to your XML files. It can be used on XML that looks ugly (e.g. any generated XML) to transform it to a nicely looking XML that can be read by humans.


Author(s):

Version:

  • Release: @package_version@

Copyright:

  • 2003-2008 Stephan Schmidt <schst@php.net>

Methods


Inherited Variables

Inherited Methods


Class Details

[line 163]
XML_Beautifier is a class that adds linebreaks and indentation to your XML files. It can be used on XML that looks ugly (e.g. any generated XML) to transform it to a nicely looking XML that can be read by humans.

It removes unnecessary whitespace and adds indentation depending on the nesting level.

It is able to treat tags, data, processing instructions comments, external entities and the XML prologue.

XML_Beautifier is using XML_Beautifier_Tokenizer to parse an XML document with a SAX based parser and builds tokens of tags, comments, entities, data, etc. These tokens will be serialized and indented by a renderer with your indent string.

Example 1: Formatting a file

  1.  require_once 'XML/Beautifier.php';
  2.  $fmt = new XML_Beautifier();
  3.  $result $fmt->formatFile('oldFile.xml''newFile.xml');

Example 2: Formatting a string

  1.  require_once 'XML/Beautifier.php';
  2.  $xml '<root><foo   bar = "pear"/></root>';
  3.  $fmt = new XML_Beautifier();
  4.  $result $fmt->formatString($xml);



[ Top ]


Method Detail

XML_Beautifier (Constructor)   [line 199]

XML_Beautifier XML_Beautifier( [array $options = array()])

Constructor

This is only used to specify the options of the beautifying process.

  • Access: public

Parameters:

array   $options   —  options that override default options

[ Top ]

apiVersion   [line 392]

string apiVersion( )

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

[ Top ]

formatFile   [line 271]

mixed formatFile( string $file, [mixed $newFile = null], [string $renderer = "Plain"])

format a file or URL
  • Return: XML string of no file should be written, true if file could be written
  • Todo: PEAR CS - should require_once be include_once?
  • Throws: PEAR_Error
  • Access: public
  • Uses: _loadRenderer() - to load the desired renderer

Parameters:

string   $file   —  filename
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
string   $renderer   —  Renderer to use, default is the plain xml renderer

[ Top ]

formatString   [line 326]

string formatString( string $string, [string $renderer = "Plain"])

format an XML string
  • Return: formatted XML string
  • Todo: PEAR CS - should require_once be include_once?
  • Throws: PEAR_Error
  • Access: public

Parameters:

string   $string   —  XML
string   $renderer   —  the renderer type

[ Top ]

resetOptions   [line 212]

void resetOptions( )

reset all options to default options

[ Top ]

setOption   [line 230]

void setOption( string $name, mixed $value)

set an option

You can use this method if you do not want to set all options in the constructor


Parameters:

string   $name   —  option name
mixed   $value   —  option value

[ Top ]

setOptions   [line 247]

void setOptions( array $options)

set several options at once

You can use this method if you do not want to set all options in the constructor


Parameters:

array   $options   —  an options array

[ Top ]


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