php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #34707 Cannot reuse XML parser, get "junk after document element" error message
Submitted: 2005-10-02 16:58 UTC Modified: 2005-10-03 09:07 UTC
Votes:6
Avg. Score:4.3 ± 0.9
Reproduced:5 of 5 (100.0%)
Same Version:0 (0.0%)
Same OS:1 (20.0%)
From: apc at hotmail dot kg Assigned:
Status: Wont fix Package: XML related
PHP Version: 4.4.0 OS: Windows XP Pro SP2
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: apc at hotmail dot kg
New email:
PHP Version: OS:

 

 [2005-10-02 16:58 UTC] apc at hotmail dot kg
Description:
------------
When I try to parse XML into struct twice using the same parser - second attempt fails.

Reproduce code:
---------------
<?php
$t=('../test/eg_snews.xml'); // any XML file

      $XMLContent = file_get_contents($t);

      $th = xml_parser_create(); 

		echo "<hr>";
      var_dump(xml_parse_into_struct ($th, $XMLContent, $V)); ;
      echo "<br>Result size: ".sizeof($V);
		echo "<br>Error code: ".$ec=xml_get_error_code($th);
  		echo "<br>Error text: ".xml_error_string($ec);      

		echo "<hr>";
      var_dump(xml_parse_into_struct ($th, $XMLContent, $V)); ;
      echo "<br>Result size: ".sizeof($V);
		echo "<br>Error code: ".$ec=xml_get_error_code($th);
  		echo "<br>Error text: ".xml_error_string($ec);      
?>

Expected result:
----------------
int(1) 
Result size: 301
Error code: 0
Error text: 

int(1) 
Result size: 301
Error code: 0
Error text: 

Actual result:
--------------
int(1) 
Result size: 301
Error code: 0
Error text: 

int(0) 
Result size: 0
Error code: 9
Error text: junk after document element

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-10-03 08:46 UTC] chregu@php.net
Simply, you can't use the same parser twice... Just make a new 
one for the second parsing.
 [2005-10-03 09:07 UTC] apc at hotmail dot kg
It's very bad for performance - creating new parser takes long time relatively to parse time... So if I have to do 10 parses I'll spend 0.05 sec creating parsers and only 0.001 sec in actual parsing.

Also - for what I have ability to create and destroy parsers without reusing created?.. 

And, at last - no single note about "You cannot use parser twice!"
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 05:01:30 2024 UTC