1
也許我誤解了一些東西,但我的下面的例子總是在屏幕上打印「XML是有效的」,這是如何可能的,因爲XML顯然被破壞了?順便說一句,我在PHP 5.5.6上。PHP XMLReader :: VALIDATE,總是有效
// index.php
<?php
/*
* PHP XMLReader - Check if a xml document is valid
*/
$reader = new XMLReader();
//$reader->open('./valid.xml');
$reader->open('./invalid.xml');
// Set parser options - you must set this in order to use isValid method
$reader->setParserProperty(\XMLReader::VALIDATE, true);
if ($reader->isValid()) {
echo "The XML is valid";
} else {
echo "The XML is NOT valid";
}
和XML
// invalid.xml
<?xmlthisisnotvalid version="1.0" encoding="ISO-8859-1"?>
<note>
<to unclosedattribute=">Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>