xref: /PHP-8.2/ext/xmlreader/tests/013.phpt (revision 74859783)
1--TEST--
2XMLReader: Schema validation
3--EXTENSIONS--
4xmlreader
5--SKIPIF--
6<?php if (!method_exists('XMLReader','setSchema')) die('skip XMLReader::setSchema() not supported');?>
7--FILE--
8<?php
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(__DIR__ . '/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(__DIR__ . '/013.xsd');
41while($reader->read() && $reader->nodeType != XMLReader::ELEMENT);
42$reader->close();
43
44?>
45--EXPECTF--
46string(3) "123"
47string(3) "456"
48===FAIL===
49
50Warning: XMLReader::read(): Element 'foo': %s
51