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