Bug #60792 [Opn->Nab]: XML parser stops on multiple XML declarations
| From: | kalle@php.net | Date: | Sat, 22 Jul 2017 22:02:34 +0000 |
| Subject: | Bug #60792 [Opn->Nab]: XML parser stops on multiple XML declarations | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-210208@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=60792&edit=1
ID: 60792
Updated by: kalle@php.net
Reported by: Daniellehr at gmx dot de
Summary: XML parser stops on multiple XML declarations
-Status: Open
+Status: Not a bug
Type: Bug
Package: *XML functions
Operating System: Ubuntu
PHP Version: 5.3.9
Block user comment: N
Private report: N
New Comment:
If you want to parse in chunks, you need to use the $is_final parameter of xml_parse().
For some reason xml_parse() rejects the second call to xml_parse(), if the xml is identifical to the
previous chunk or the current buffer (I did not read the code internally).
This however makes the code parse in chunks:
xml_parse($p, $xml);
xml_parse($p, $xml2, true);
Previous Comments:
------------------------------------------------------------------------
[2016-02-15 00:39:59] anrdaemon at freemail dot ru
This is an expected behavior. You must recreate the parser for a new document.
Not. A. Bug.
------------------------------------------------------------------------
[2012-01-18 14:29:13] Daniellehr at gmx dot de
Description:
------------
I am working with socket streams and the XMPP protocol.
In a while it happens that a connection has to be replaced with a new one.
This can be done with sending the root node again to the server, and the server
then replies with a new root node too.
This root node includes the XML declaration (<?xml ... ?>), but apparently the
parser seems to stop at that point, where a new XML declaration occurs.
So I have to filter those strings out manually, that's not the expected behavior
I wished to have.
This has been tested with PHP 5.3.5 and 5.3.9
Test script:
---------------
<?php
$p = xml_parser_create();
xml_set_element_handler($p, 'open', 'close');
function open($p, $tag) {
echo "opened tag $tag\n";
}
function close($p, $tag) {
echo "closed tag $tag\n";
}
$xml = "<?xml version='1.0' ?><stream><tag></tag>";
$xml2 = '</stream>';
xml_parse($p, $xml);
xml_parse($p, $xml);
xml_parse($p, $xml2);
Expected result:
----------------
opened tag STREAM
opened tag TAG
closed tag TAG
opened tag STREAM
opened tag TAG
closed tag TAG
closed tag STREAM
Actual result:
--------------
opened tag STREAM
opened tag TAG
closed tag TAG
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=60792&edit=1