定義和用法
XML 是一種 mark-up 語言,用於在網絡上共享數據,XML 用於人類 read-able 和機器 read-able。 XMLReader 擴展用於讀取/檢索 XML 文檔的內容,即使用 XMLReader 類的方法可以讀取 XML 文檔的每個節點。
這個XMLReader::isValid()XMLReader 類的函數用於驗證讀取/解析文檔的當前節點是否有效。
用法
XMLReader::isValid();
參數
該函數不接受任何參數。
返回值
此函數返回一個布爾值,如果解析的文檔有效,則該值是 TRUE,如果是無效的,則該值是 FALSE。
PHP版本
這個函數最初是在 PHP 版本 5 中引入的,並且適用於所有後續版本。
示例
下麵的例子演示了XMLReader::isValid()函數∨data.xml
<dataaa>
<name>Raju</name>
<age>32</age>
<phone>9848022338</phone>
<city>Hyderabad</city>
</data>
sample.php
<?php
//Creating an XMLReader
$reader = new XMLReader();
//Opening a reader
$reader->open("test.xml");
//Setting the parser property
//$xml->setParserProperty($reader->VALIDATE, true);
$bool = $reader->isValid();
if($bool){
print("Current node is valid");
} else {
print("Current node is invalid");
}
//Closing the reader
$reader->close();
?>
這將產生以下結果 -
Current node is invalid
相關用法
- PHP XMLReader::getParserProperty()用法及代碼示例
- PHP XMLReader::open()用法及代碼示例
- PHP XMLReader::moveToAttributeNs()用法及代碼示例
- PHP XMLReader::moveToNextAttribute()用法及代碼示例
- PHP XMLReader::moveToAttribute()用法及代碼示例
- PHP XMLReader::next()用法及代碼示例
- PHP XMLReader::setParserProperty()用法及代碼示例
- PHP XMLReader::expand()用法及代碼示例
- PHP XMLReader::lookupNamespace()用法及代碼示例
- PHP XMLReader::moveToElement()用法及代碼示例
- PHP XMLReader::moveToAttributeNo()用法及代碼示例
- PHP XMLReader::getAttributeNs()用法及代碼示例
- PHP XMLReader::XML()用法及代碼示例
- PHP XMLReader::read()用法及代碼示例
- PHP XMLReader::readOuterXml()用法及代碼示例
- PHP XMLReader::moveToFirstAttribute()用法及代碼示例
- PHP XMLReader readOuterXml()用法及代碼示例
- PHP XMLReader setRelaxNGSchema()用法及代碼示例
- PHP XMLReader getAttributeNo()用法及代碼示例
- PHP XMLReader getParserProperty()用法及代碼示例
注:本文由純淨天空篩選整理自 PHP - XMLReader::isValid() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。