xref: /PHP-7.0/ext/xmlreader/tests/013.phpt (revision 610c7fbe)
1--TEST--
2XMLReader: Schema validation
3--SKIPIF--
4<?php if (!extension_loaded('xmlreader')) die('skip');?>
5<?php if (!method_exists('XMLReader','setSchema')) die('skip XMLReader::setSchema() not supported');?>
6--FILE--
7<?php
8/* $Id$ */
9
10$xml =<<<EOF
11<?xml version="1.0" encoding="UTF-8" ?>
12<items>
13  <item>123</item>
14  <item>456</item>
15</items>
16EOF;
17
18$reader = new XMLReader();
19$reader->XML($xml);
20$reader->setSchema(dirname(__FILE__) . '/013.xsd');
21while($reader->read()) {
22	if ($reader->nodeType == XMLReader::ELEMENT && $reader->name == 'item') {
23		$reader->read();
24		var_dump($reader->value);
25	}
26}
27$reader->close();
28
29?>
30===FAIL===
31<?php
32
33$xml =<<<EOF
34<?xml version="1.0" encoding="UTF-8" ?>
35<foo/>
36EOF;
37
38$reader = new XMLReader();
39$reader->XML($xml);
40$reader->setSchema(dirname(__FILE__) . '/013.xsd');
41while($reader->read() && $reader->nodeType != XMLReader::ELEMENT);
42$reader->close();
43
44?>
45===DONE===
46--EXPECTF--
47string(3) "123"
48string(3) "456"
49===FAIL===
50
51Warning: XMLReader::read(): Element 'foo': %s
52===DONE===
53