php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #55353 XML Error in 5.3.6
Submitted: 2011-08-03 10:34 UTC Modified: 2016-12-01 12:22 UTC
Votes:1
Avg. Score:1.0 ± 0.0
Reproduced:0 of 1 (0.0%)
From: pim at highattention dot nl Assigned: cmb (profile)
Status: Not a bug Package: *XML functions
PHP Version: 5.3.6 OS:
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: pim at highattention dot nl
New email:
PHP Version: OS:

 

 [2011-08-03 10:34 UTC] pim at highattention dot nl
Description:
------------
---
From manual page: http://www.php.net/function.xml-parse%23Description
---
We migrate from 5.2 to 5.3 and gives a error:
Parser error #73: > required on line 6, column 14.

Test script:
---------------
PHP
-----------------------------------------
		$this->_parserMemory = array();
		$parser = xml_parser_create('UTF-8');
		
		xml_set_object($parser, $this);
		xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
		xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
		xml_parser_set_option($parser, XML_OPTION_TARGET_ENCODING, 'UTF-8');		
		xml_set_element_handler($parser, "_xmlTagOpen", "_xmlTagClose");
		xml_set_character_data_handler($parser, "_xmlCdata");
		
		if (!xml_parse($parser, $xml)) {
			$this->_children = array();
			$error_code = xml_get_error_code($parser);
			$error_string = xml_error_string($error_code);
			$current_line = xml_get_current_line_number($parser);
			$current_column = xml_get_current_column_number($parser);
			
			throw new Idify_FileHandler_Xml_Exception("In {$this->_filename} : Parser error #{$error_code}: {$error_string} on line {$current_line}, column {$current_column}.");
		}
		
		unset($this->_parserMemory);
		xml_parser_free($parser);

----------------------------------------
XML
----------------------------------------
<simplexml>
	<name>PageControl</name>
	<title>Paginabeheer</title>
	<version>1.0.0</version>
	<cms_routes>
		<index type="default" inMenu="true" authlevel="50">
			<title>Overzicht</title>
			<parts>
				<part>pagecontrol</part>
				<part>*</part>
		

Expected result:
----------------
No error, system gives a new error on a attribute. Exact xml in 5.2 and 5.3, but 
in 5.3, he gives a error on a attribute.

And gives a error on: <?xml version="1.0"?>, when I remove this line the error 
disapear


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-08-03 10:36 UTC] pajoye@php.net
-Status: Open +Status: Feedback
 [2011-08-03 10:36 UTC] pajoye@php.net
Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves. 

A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external 
resources such as databases, etc. If the script requires a 
database to demonstrate the issue, please make sure it creates 
all necessary tables, stored procedures etc.

Please avoid embedding huge scripts into the report.


 [2011-08-03 10:47 UTC] pim at highattention dot nl
-Status: Feedback +Status: Open
 [2011-08-03 10:47 UTC] pim at highattention dot nl
<?php
	function parse( $xml ){
    
		//$this->_parserMemory = array();
		$parser = xml_parser_create('UTF-8');
		
		xml_set_object($parser, $this);
		xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
		xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
		xml_parser_set_option($parser, XML_OPTION_TARGET_ENCODING, 'UTF-
8');		
		xml_set_element_handler($parser, "_xmlTagOpen", "_xmlTagClose");
		xml_set_character_data_handler($parser, "_xmlCdata");
		
		if (!xml_parse($parser, $xml)) {
			$this->_children = array();
			$error_code = xml_get_error_code($parser);
			$error_string = xml_error_string($error_code);
			$current_line = xml_get_current_line_number($parser);
			$current_column = 
xml_get_current_column_number($parser);
			
			echo ("Parser error #{$error_code}: {$error_string} on 
line {$current_line}, column {$current_column}.");
		}
		
		//unset($this->_parserMemory);
		xml_parser_free($parser);
     }
     
    $xml = '<simplexml>
				<name>PageControl</name>
				<title>Paginabeheer</title>
				<version>1.0.0</version>
					<cms_routes>
						<index type="default" 
inMenu="true" authlevel="50">
							<title>Overzicht</title>
								<parts>
								
<part>pagecontrol</part>
								<part>*</part>
                            </title>
                         </index>
                    </cms>
                </version>
          	</simplexml>';
    parse( $xml );
         
?>
 [2016-02-15 01:05 UTC] anrdaemon at freemail dot ru
https://bugs.php.net/bug.php?id=55353
SIMPLEXML []
    NAME []
        #text: PageControl
    /NAME
    TITLE []
        #text: Paginabeheer
    /TITLE
    VERSION []
        #text: 1.0.0
    /VERSION
    CMS_ROUTES []
        INDEX {"TYPE":"default","INMENU":"true","AUTHLEVEL":"50"}
            TITLE []
                #text: Overzicht
            /TITLE
            PARTS []
                PART []
                    #text: pagecontrol
                /PART
                PART []
                    #text: *
                /PART
XML Parser error 'Mismatched tag' in (data stream):311(13,37)
Stack trace:
#0 …/XmlParser.php(106): org\rootdir\Wrapper\XmlParser->parse('<simplexml>\n\t\t\t...', true)
#1 …/xml-test.php(200): org\rootdir\Wrapper\XmlParser->parseString('<simplexml>\n\t\t\t...')
#2 {main}

Which is 100% expected considering the open tag is "<parts>" but closing one is "</title>". And there's one more mismatch too: "<cms_routes>"/"</cms>", also "</version>" closed twice.

After fixing the three mentioned issues with provided sample, it parses perfectly.
 [2016-12-01 12:22 UTC] cmb@php.net
-Status: Open +Status: Not a bug -Assigned To: +Assigned To: cmb
 [2016-12-01 12:22 UTC] cmb@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

Indeed, invalid XML is not necessarily supported by the XML Parser.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Nov 12 03:01:29 2024 UTC