You are here: Re: [PHP] XML Parser set option « PHP « IT news, forums, messages
Re: [PHP] XML Parser set option

Posted by ondrej on 12/20/05 12:44

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@kmit.sk)

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация