XMLReader::getParserProperty()函數是PHP中的內置函數,用於檢查是否設置了指定的屬性。
用法:
bool XMLReader::getParserProperty( int $property )
參數:該函數接受單個參數$property,該參數保存一個與PARSER Options常量之一相對應的整數。解析器選項常量列表如下:
- XMLReader::LOADDTD(1)這將加載DTD,但不會驗證。
- XMLReader::DEFAULTATTRS(2)這將加載DTD和默認屬性,但不會驗證。
- XMLReader::VALIDATE(3)這將加載DTD並在解析時進行驗證。
- XMLReader::SUBST_ENTITIES(4)這將替代實體並擴展引用。
返回值:如果成功,此函數將返回TRUE,否則將返回FALSE。
異常:該函數在錯誤時引發XMLReaderException。
以下示例說明了PHP中的XMLReader::getParserProperty()函數:
範例1:
- data.xml
<?xml version="1.0" encoding="utf-8"?> <div xmlns:x="geeksforgeeks"> <x:h1 x:attrib="value"> Namespaced Text </x:h1> </div>
- index.php
<?php // Create a new XMLReader instance $XMLReader = new XMLReader(); // Open the XML file with sample XML $XMLReader->open('data.xml'); // Check if XMLReader::VALIDATE is set or not $isProperty = $XMLReader-> getParserProperty(XMLReader::VALIDATE); if (!$isProperty) { echo 'Property isn\'t set.'; } ?>
- 輸出:
Property isn't set.
範例2:
- data.xml
<?xml version="1.0" encoding="utf-8"?> <div xmlns:x="geeksforgeeks"> <x:h1 x:attrib="value"> Namespaced Text </x:h1> </div>
- index.php
<?php // Create a new XMLReader instance $XMLReader = new XMLReader(); // Open the XML file with sample XML $XMLReader->open('data.xml'); // Set the Parser Property $XMLReader->setParserProperty( XMLReader::VALIDATE, true); // Check if XMLReader::VALIDATE // is set or not $isProperty = $XMLReader->getParserProperty( XMLReader::VALIDATE); if ($isProperty) { echo 'Property is set.'; } ?>
- 輸出:
Property is set.
參考:https://www.php.net/manual/en/xmlreader.getparserproperty.php
相關用法
- PHP XMLReader XML()用法及代碼示例
- PHP XMLReader close()用法及代碼示例
- PHP XMLReader getAttributeNs()用法及代碼示例
- PHP XMLReader open()用法及代碼示例
- PHP XMLReader moveToFirstAttribute()用法及代碼示例
- PHP XMLReader moveToNextAttribute()用法及代碼示例
- PHP XMLReader readString()用法及代碼示例
- PHP XMLReader readInnerXml()用法及代碼示例
- PHP XMLReader readOuterXml()用法及代碼示例
- PHP XMLReader setRelaxNGSchema()用法及代碼示例
- PHP XMLReader setParserProperty()用法及代碼示例
- PHP XMLReader setRelaxNGSchemaSource()用法及代碼示例
- PHP XMLReader setSchema()用法及代碼示例
注:本文由純淨天空篩選整理自gurrrung大神的英文原創作品 PHP | XMLReader getParserProperty() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。