php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #1212 XML-Parser (Attributes) behave non-deterministic
Submitted: 1999-03-08 06:52 UTC Modified: 1999-03-09 08:03 UTC
From: cbi at cebis dot net Assigned:
Status: Closed Package: Misbehaving function
PHP Version: 3.0.7 OS: Linux 2.0.36
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: cbi at cebis dot net
New email:
PHP Version: OS:

 

 [1999-03-08 06:52 UTC] cbi at cebis dot net
How to reproduce the problem:

--- PHP script starts here ---
<?

$file = "data.xml";

function startElement($parser, $name, $attrs)
{
	if ($name=="PRODUKT") {
		print "Produkt-ID ".$attrs["ID"]."<BR>";
	}	
}

function endElement($parser, $name )
{}

$xml_parser = xml_parser_create();
xml_set_element_handler($xml_parser, "startElement", "endElement");
if (!($fp = fopen($file, "r"))) {
	die("could not open XML input");
}

while ($data = fread($fp, 4096)) {
	if (!xml_parse($xml_parser, $data, feof($fp))) {
		die(sprintf("XML error: %s at line %d",
		xml_error_string(xml_get_error_code($xml_parser)),
		xml_get_current_line_number($xml_parser)));
    }
}

xml_parser_free($xml_parser);

?>
--- end of script ---

--- XML data file ---
<?xml version="1.0" standalone="yes"?>

<import>


<produkt id="100">

	<text>iMac</text>

</produkt>


<produkt id="101">

	<text>IBM</text>

</produkt>

<produkt id="102">

	<text>Yakumo</text>

</produkt>

<produkt id="103">

	<text>IIyama</text>

</produkt>

<produkt id="104">

	<text>Microsoft</text>

</produkt>

<produkt id="105">

	<text>Noname</text>

</produkt>

<produkt id="106">

	<text>test</text>

</produkt>

<produkt id="107">

	<text>gaudi</text>

</produkt>

<produkt id="108">

	<text>icat sucks</text>

</produkt>

</import>
---end of XML---


now run the script on the xml-file, the output looks like this

--- sample output 1 ---
Produkt-ID 100
Produkt-ID 101
Produkt-ID 102
Produkt-ID 103
Produkt-ID 104
Produkt-ID 105
Produkt-ID 106
Produkt-ID 107
Produkt-ID 108
--- end ------------

now reload the page a couple of times, I sometimes get

-- sample output 2 ---
Produkt-ID 100P
Produkt-ID 101P
Produkt-ID 102P
Produkt-ID 103P
Produkt-ID 104P
Produkt-ID 105P
Produkt-ID 106P
Produkt-ID 107P
Produkt-ID 108P
--- end ----

That means some random characters are appended to the content of $attrs["ID"]


My PHP-Configuration

./configure --with-xml --with-gd=../gd1.3 --with-sybase-ct --enable-track-vars --with-apache=../apache_1.3.4

Expat Version 1.0.2

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [1999-03-09 08:03 UTC] steffann
Looks like the same bug as in #1116 (xml_utf8_decode didn't add a 0 to the end of the string). Fixed in cvs.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sun Jul 06 19:01:36 2025 UTC