php.net |  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
Votes:2
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
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: Daniellehr at gmx dot de
New email:
PHP Version: OS:

 

 [2012-01-18 14:29 UTC] 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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

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] kalle@php.net
-Status: Open +Status: Not a bug
 [2017-07-22 22:02 UTC] kalle@php.net
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-2022 The PHP Group
All rights reserved.
Last updated: Thu Jan 27 21:03:35 2022 UTC