|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #61587 XMLReader - invalid schema error using ampersands
Submitted: 2012-03-31 22:59 UTC Modified: 2013-10-03 12:59 UTC
From: ryan dot brothers at gmail dot com Assigned:
Status: Not a bug Package: XML Reader
PHP Version: 5.3.10 OS: Linux
Private report: No CVE-ID: None
 [2012-03-31 22:59 UTC] ryan dot brothers at gmail dot com
In the following test script, the example xml is valid against the supplied schema.  DOMDocument displays no schema errors as expected, but XMLReader displays a schema violation.  I was expecting XMLReader to not report any schema violations.

Test script:

$xml = '<user name="a &amp; b"/>';

$schema = '<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="">
	<xs:element name="user">
			<xs:attribute name="name" use="required">
					<xs:restriction base="xs:string">
						<xs:enumeration value="a &amp; b"/>

// create temp file with schema
$schema_file = tempnam(sys_get_temp_dir(), '');

file_put_contents($schema_file, $schema);

// test with DOMDocument
$dom = new DOMDocument;


// test with XMLReader
$xmlreader = new XMLReader;


while ($xmlreader->read() == true);


// delete temp file

Expected result:
No output

Actual result:
Warning: XMLReader::read(): Element 'user', attribute 'name': [facet 'enumeration'] The value 'a &#38; b' is not an element of the set {'a & b'}. in test.php on line 38

Warning: XMLReader::read(): Element 'user', attribute 'name': 'a &#38; b' is not a valid value of the local atomic type. in test.php on line 38


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2013-10-03 12:59 UTC]
-Status: Open +Status: Not a bug
 [2013-10-03 12:59 UTC]
I'm not an (lib)xml expert, but using LIBXML_NOENT as parsing options for the XMLReader aligns the behaviour:

$xmlreader->xml($xml, null, LIBXML_NOENT);
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Tue Dec 01 06:01:23 2020 UTC