IsleX
Новичок
XML, странное поведение обработчика символьных данных
Странно работает обработчик сивольных данных (characterData).
Пример:
$xmlString[0] обрабатывает нормально, но в варианте с $xmlString[1] characterData вызывается 3 раза..
Цитата из мануала, с комментов (http://php.rinet.ru/manual/ru/function.xml-set-character-data-handler.php#18609): Цитата:
Странно работает обработчик сивольных данных (characterData).
Пример:
PHP:
<?
$xmlString[0] = "<AAA>test test test</AAA>";
$xmlString[1] = "<AAA>test & test</AAA>";
function startElement($xml_parser, $name, $attrs) {}
function endElement($xml_parser, $name) {}
function characterData($xml_parser, $data) {
global $i;
@$i++;
echo $i.". ".htmlspecialchars($data)."<br>";
}
$xml_parser = xml_parser_create();
xml_set_element_handler($xml_parser, "startElement", "endElement");
xml_set_character_data_handler($xml_parser, "characterData");
xml_parse($xml_parser, $xmlString[1]);
?>
Цитата из мануала, с комментов (http://php.rinet.ru/manual/ru/function.xml-set-character-data-handler.php#18609): Цитата:
Помогите обойти проблему, необходимо сделать обработку содержимого <AAA> за Один разthe function handler is called several times when it parses the character data. It doesn't return the entire string as it suggests. There are special exceptions that will always force the parser to stop scanning and call the character data handler. This is when:
- The parser runs into an Entity Declaration, such as & (&) or ' (?)
- The parser finishes parsing an entity
- The parser runs into the new-line character (\n)
- The parser runs into a series of tab characters (\t)

