php.net |  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
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: ryan dot brothers at gmail dot com
New email:
PHP Version: OS:

 

 [2012-03-31 22:59 UTC] ryan dot brothers at gmail dot com
Description:
------------
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:
---------------
<?php
error_reporting(E_ALL);

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

$schema = '<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
	<xs:element name="user">
		<xs:complexType>
			<xs:attribute name="name" use="required">
				<xs:simpleType>
					<xs:restriction base="xs:string">
						<xs:enumeration value="a &amp; b"/>
					</xs:restriction>
				</xs:simpleType>
			</xs:attribute>
		</xs:complexType>
	</xs:element>
</xs:schema>';

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

file_put_contents($schema_file, $schema);

// test with DOMDocument
$dom = new DOMDocument;
$dom->loadXML($xml);

$dom->schemaValidate($schema_file);

// test with XMLReader
$xmlreader = new XMLReader;
$xmlreader->xml($xml);

$xmlreader->setSchema($schema_file);

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

$xmlreader->close();

// delete temp file
unlink($schema_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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-10-03 12:59 UTC] mike@php.net
-Status: Open +Status: Not a bug
 [2013-10-03 12:59 UTC] mike@php.net
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-2024 The PHP Group
All rights reserved.
Last updated: Fri Dec 27 12:01:29 2024 UTC