Добро пожаловать на форум PHP программистов!
За последние 24 часа нас посетили 17170 программистов и 1833 робота. Сейчас ищут 1699 программистов ...

Options

Вернуться к: XML_Beautifier

Options

Options – List of all XML_Beautifier options

Options let you influence the beautifiying process. They are passed to the renderer and thus, you have to check, whether the renderer you are using supports the options you want to use.

As there currently is only one renderer (Plain) available, you should not worry about this too much.

Options can be passed as an associative array to the constructor of XML_Beautifier. You may also use setOption(), or setOptions() to set one or more options after the instance of XML_Beautifier has been created.

All available options

Here is a list of all options supported by XML_Beautifier.

XML_Beautifier options
Option Possible values Default Description
removeLineBreaks TRUE or FALSE TRUE Sets, whether linebreaks should be stripped from cdata sections
indent any string " " (4 spaces) The string passed to this option will be used to indent the tags in one level.
linebreak any string "\n" The string passed to this option will be used for linebreaks You should use "\n" or "\r\n".
caseFolding TRUE or FALSE FALSE Disable or enable case folding for tags and attributes
caseFoldingTo "uppercase" or "lowercase" "uppercase" Can be used, if caseFolding is set to TRUE to define whether tags and attributes should be converted to upper- or lowercase
normalizeComments FALSE or TRUE FALSE If set to true, all adjacent whitespaces in an XML comment will be converted to one space. This will convert comments with more than one line to a comment with one line.
maxCommentLine integer -1 Maximum length of comment line. If a comment exceeds this limit, it will be wrapped automatically. If set to -1 the line length is unlimited.
multilineTags TRUE or FALSE FALSE If set to true, a linebreak will be added inside the tags after each attribute and attributes will be indeted.

Options example

The following example shows how to set options for XML_Beautifier.

Using setOptions() and setOption()

<?php
require_once "XML/Beautifier.php";
$options = array(
                    
"caseFolding"       => true,
                    
"caseFoldingTo"     => "uppercase",
                    
"normalizeComments" => true
                
);

$fmt = new XML_Beautifier($options);
$result $fmt->formatFile('originalFile.xml''outputFile.xml');
?>

Options example setting options at a later point

The following example shows how to set options for XML_Beautifier, if the instance already has been created.

XML_Beautifier options

<?php
require_once "XML/Beautifier.php";
$fmt = new XML_Beautifier();
$options = array(
                    
"caseFolding"       => true,
                    
"caseFoldingTo"     => "uppercase",
                    
"normalizeComments" => true
                
);

$fmt->setOptions($options);
$fmt->setOption("indent""\t");
$result $fmt->formatFile('originalFile.xml''outputFile.xml');
?>


Вернуться к: XML_Beautifier

© 2024 «PHP.RU — Сообщество PHP-Программистов»
Главная | Форум | Реклама на сайте | Контакты VIP Сувениры
Разработка компании ODware