xref: /PHP-8.0/ext/xmlreader/tests/013.phpt (revision f8d79582)
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
9$xml =<<<EOF
10<?xml version="1.0" encoding="UTF-8" ?>
11<items>
12  <item>123</item>
13  <item>456</item>
14</items>
15EOF;
16
17$reader = new XMLReader();
18$reader->XML($xml);
19$reader->setSchema(__DIR__ . '/013.xsd');
20while($reader->read()) {
21    if ($reader->nodeType == XMLReader::ELEMENT && $reader->name == 'item') {
22        $reader->read();
23        var_dump($reader->value);
24    }
25}
26$reader->close();
27
28?>
29===FAIL===
30<?php
31
32$xml =<<<EOF
33<?xml version="1.0" encoding="UTF-8" ?>
34<foo/>
35EOF;
36
37$reader = new XMLReader();
38$reader->XML($xml);
39$reader->setSchema(__DIR__ . '/013.xsd');
40while($reader->read() && $reader->nodeType != XMLReader::ELEMENT);
41$reader->close();
42
43?>
44--EXPECTF--
45string(3) "123"
46string(3) "456"
47===FAIL===
48
49Warning: XMLReader::read(): Element 'foo': %s
50