|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #60792 XML parser stops on multiple XML declarations
Submitted: 2012-01-18 14:29 UTC Modified: 2017-07-22 22:02 UTC
Avg. Score:1.5 ± 0.5
Reproduced:1 of 2 (50.0%)
Same Version:1 (100.0%)
Same OS:0 (0.0%)
From: Daniellehr at gmx dot de Assigned:
Status: Not a bug Package: *XML functions
PHP Version: 5.3.9 OS: Ubuntu
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
2 + 20 = ?
Subscribe to this entry?

 [2012-01-18 14:29 UTC] Daniellehr at gmx dot de
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:
$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


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2016-02-15 00:39 UTC] anrdaemon at freemail dot ru
This is an expected behavior. You must recreate the parser for a new document.
Not. A. Bug.
 [2017-07-22 22:02 UTC]
-Status: Open +Status: Not a bug
 [2017-07-22 22:02 UTC]
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);
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed May 29 08:01:32 2024 UTC