xref: /PHP-7.3/ext/xmlreader/tests/008.phpt (revision 782352c5)
1--TEST--
2XMLReader: libxml2 XML Reader, DTD
3--SKIPIF--
4<?php if (!extension_loaded("xmlreader")) print "skip"; ?>
5--FILE--
6<?php
7
8$xmlstring = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>
9<!DOCTYPE LIST SYSTEM "dtdexample.dtd">
10<LIST>
11<MOVIE ID="x200338360">
12<TITLE>Move Title 1</TITLE>
13<ORGTITLE/><LOC>Location 1</LOC>
14<INFO/>
15</MOVIE>
16<MOVIE ID="m200338361">
17<TITLE>Move Title 2</TITLE>
18<ORGTITLE/>
19<LOC>Location 2</LOC>
20<INFO/>
21</MOVIE>
22</LIST>';
23
24$dtdfile = rawurlencode(dirname(__FILE__)) . '/dtdexample.dtd';
25$file = dirname(__FILE__) . '/_008.xml';
26file_put_contents($file, $xmlstring);
27
28
29$reader = new XMLReader();
30$reader->open($file);
31$reader->setParserProperty(XMLREADER::LOADDTD, TRUE);
32$reader->setParserProperty(XMLREADER::VALIDATE, TRUE);
33while($reader->read());
34if ($reader->isValid()) {
35	echo "file DTD: ok\n";
36}
37$reader->close();
38unlink($file);
39
40$xmlstring = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>
41<!DOCTYPE LIST SYSTEM "file:///' . $dtdfile. '">
42<LIST>
43<MOVIE ID="x200338360">
44<TITLE>Move Title 1</TITLE>
45<ORGTITLE/><LOC>Location 1</LOC>
46<INFO/>
47</MOVIE>
48<MOVIE ID="m200338361">
49<TITLE>Move Title 2</TITLE>
50<ORGTITLE/>
51<LOC>Location 2</LOC>
52<INFO/>
53</MOVIE>
54</LIST>';
55
56$reader = new XMLReader();
57$reader->XML($xmlstring);
58
59$reader->setParserProperty(XMLREADER::LOADDTD, TRUE);
60$reader->setParserProperty(XMLREADER::VALIDATE, TRUE);
61while($reader->read());
62if ($reader->isValid()) {
63	echo "string DTD: ok\n";
64}
65?>
66===DONE===
67--EXPECT--
68file DTD: ok
69string DTD: ok
70===DONE===
71