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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
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

Add a Patch

Pull Requests

Add a Pull Request

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: Sat Apr 20 02:01:29 2024 UTC