php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #46978 XMLReader::setRelaxNGSchema() fails
Submitted: 2008-12-30 21:04 UTC Modified: 2008-12-31 00:33 UTC
From: remy dot damour at laposte dot net Assigned: rrichards
Status: Not a bug Package: XML Reader
PHP Version: 5.2.8 OS: ubuntu intrepid
Private report: No CVE-ID:
 [2008-12-30 21:04 UTC] remy dot damour at laposte dot net
Description:
------------
Each time I call XMLReader::setRelaxNGSchema() or XMLReader::setRelaxNGSchemaSource() it ends up with an error message.

My relax-ng content looks valid, it's succefully loaded and used for parsing xml with both xmllint (from package libxml2-utils) and sun-microsystem "msv" (https://msv.dev.java.net/) validator.

Reproduce code:
---------------
<?php
$rng_schema = <<<RNG
<?xml version="1.0"?>
<grammar xmlns="http://relaxng.org/ns/structure/1.0" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
	<start>
		<element name="node1"><text/></element>
	</start>
</grammar>
RNG;
$xml_reader = new XMLReader();
$xml_reader->setRelaxNGSchemaSource($rng_schema);


Expected result:
----------------
no error message

Actual result:
--------------
Warning: XMLReader::setRelaxNGSchemaSource() [xmlreader.setrelaxngschemasource]: Unable to set schema. This must be set prior to reading or schema contains errors. in /var/www/test.php on line 12

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-12-30 22:19 UTC] remy dot damour at laposte dot net
I've described my problem here too with additional details and a quick workaround using xmllint tool: http://www.qc4blog.com/?p=363

Regards,
Remy
 [2008-12-31 00:30 UTC] remy dot damour at laposte dot net
Rob,
Thanks for your help you're 100% right, loading data prior to setting relax-ng schema removes the error message.

Problem now is that relax-ng validation seems to fail:
<?php
$rng_schema = <<<RNG
<?xml version="1.0"?>
<grammar xmlns="http://relaxng.org/ns/structure/1.0" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
	<start>
		<element name="node1"><text/></element>
	</start>
</grammar>
RNG;
$xml_data = <<<XML
<?xml version="1.0"?>
<node2/>
XML;
$xml_reader = new XMLReader();
$xml_reader->xml($xml_data);
$xml_reader->setRelaxNGSchemaSource($rng_schema);
$xml_reader->setParserProperty(XMLReader::VALIDATE, true);
var_dump($xml_reader->isValid());
#expected output: bool(false)
#php output: bool(true)
?>

Output when calling xmllint:

node1.xml:2: element node2: Relax-NG validity error : Expecting element node1, got node2. node1.xml fails to validate

I've commented it here too: http://www.qc4blog.com/?p=363

Regards,
Remy
 [2008-12-31 00:33 UTC] rrichards@php.net
This is expected behavior - document needs to be set prior to setting 
the schema. I will however add a more descriptive error for this case.
 
PHP Copyright © 2001-2014 The PHP Group
All rights reserved.
Last updated: Thu Apr 24 02:02:10 2014 UTC