Re: XML Parser set option

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Amol Hatwar wrote:
Hi,

The PHP Manual entry for xml_parser_set_option lists an option called:
XML_OPTION_SKIP_WHITE. I really couldn't decipher what this option
enables or disables.

The manual entry itself is a bit terse:
"Whether to skip values consisting of whitespace characters."

Doodling around with it in code got me no luck. Any ideas on what kind
of whitespaces it does supress?

Look at this script:

<?php
$simple = "<root>\n\t</root>";

$p = xml_parser_create();

xml_parser_set_option($p, XML_OPTION_SKIP_WHITE, $argv[1]);
xml_parse_into_struct($p, $simple, $vals);

xml_parser_free($p);
echo "\nVals array\n";
print_r($vals);
?>

// sets XML_OPTION_SKIP_WHITE to false
ondrej@quax ~/tmp $ php simple.php 0
Array
(
    [0] => Array
        (
            [tag] => ROOT
            [type] => complete
            [level] => 1
            [value] =>

        )

)

// sets XML_OPTION_SKIP_WHITE to 1
ondrej@quax ~/tmp $ php simple.php 1
Array
(
    [0] => Array
        (
            [tag] => ROOT
            [type] => complete
            [level] => 1
        )

)

With XML_OPTION_SKIP_WHITE = 1 sets are whitespace chars discarded from the result. In first output is index 'value' which contains only "\n\t" - whitespace chars. Second output is without this index in array - whitespace chars are ignored.

If you have node which contains text and whitespace chars "<node> some text</node>" then whitespace chars are not discarded. Only content of nodes with whitespace chars only are discarded (<node> </node> -> <node></node>).


--
Ondrej Ivanic
(ondrej@xxxxxxx)

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux