|
PHP-Fusion
v.7.01 |
AP-Fusion
v7.02.03 |
Pimped-Fusion-AP
v0.09.03 |
| февраля 12 2012 05:16:13 |
|
xml_parser_set_optionDescriptionbool xml_parser_set_option ( resource parser, int option, mixed value )
This function returns FALSE if parser does not refer to a valid parser, or if the option could not be set. Else the option is set and TRUE is returned. The following options are available: Таблица 1. XML parser options
Пример. Отображение XML в HTML
Этот пример отображает тэги XML-документа непосредственно в тэги HTML.
Элементы, не найденные в "массиве отображения", игнорируются.
Конечно, этот пример будет работать только со специфическим типом XML-документов.
$file = "data.xml";
$map_array = array(
"BOLD" => "B",
"EMPHASIS" => "I",
"LITERAL" => "TT"
);
function startElement($parser, $name, $attrs) {
global $map_array;
if ($htmltag = $map_array[$name]) {
print "<$htmltag>";
}
}
function endElement($parser, $name) {
global $map_array;
if ($htmltag = $map_array[$name]) {
print "<$htmltag>";
}
}
function characterData($parser, $data) {
print $data;
}
$xml_parser = xml_parser_create();
// использовать выравнивание регистра, чтобы гарантированно найти тэг в $map_array
xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, true);
xml_set_element_handler($xml_parser, "startElement", "endElement");
xml_set_character_data_handler($xml_parser, "characterData");
if (!($fp = fopen($file, "r"))) {
die("could not open XML input");
}
while ($data = fread($fp, 4096)) {
if (!xml_parse($xml_parser, $data, feof($fp))) {
die(sprintf("XML error: %s at line %d",
xml_error_string(xml_get_error_code($xml_parser)),
xml_get_current_line_number($xml_parser)));
}
}
xml_parser_free($xml_parser);
|
|
| 4,253,009 уникальных посетителей | Iceberg by Harly |