XMLReader::lookupNamespace()函數是PHP中的內置函數,用於在範圍命名空間中查找給定前綴。
用法:
string XMLReader::lookupNamespace( string $prefix )
參數:該函數接受單個參數$prefix,該參數保存包含前綴的字符串。
返回值:如果成功,則此函數返回TRUE;如果失敗,則返回FALSE。
下麵給出的程序說明了PHP中的XMLReader::lookupNamespace()函數:
程序1:
文檔名稱: data.xml
<?xml version="1.0" encoding="utf-8"?>
<div xmlns:z="my_namespace">
<z:h1 z:attrib="value"> Foo Bar </z:h1>
</div>
文檔名稱: index.php
<?php
// Create a new XMLReader instance
$XMLReader = new XMLReader();
// Open the XML file
$XMLReader->open('data.xml');
// Read the node
$XMLReader->read();
// Get the namespace with prefix y
$NS = $XMLReader->lookupNamespace("y");
// Show the namespace to browser
echo $NS;
?>
輸出:
// Empty string because there is no namespace with prefix y.
程序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
$XMLReader->open('data.xml');
// Read the node
$XMLReader->read();
// Get the namespace with prefix x
$NS = $XMLReader->lookupNamespace("x");
// Show the namespace to browser
echo $NS;
?>
輸出:
geeksforgeeks
參考: https://www.php.net/manual/en/xmlreader.lookupnamespace.php
相關用法
- PHP XMLReader XML()用法及代碼示例
- PHP XMLReader getAttribute()用法及代碼示例
- PHP XMLReader moveToFirstAttribute()用法及代碼示例
- PHP XMLReader setRelaxNGSchema()用法及代碼示例
- PHP XMLReader expand()用法及代碼示例
- PHP XMLReader readString()用法及代碼示例
- PHP XMLReader setRelaxNGSchemaSource()用法及代碼示例
- PHP XMLReader setSchema()用法及代碼示例
- PHP XMLReader readInnerXml()用法及代碼示例
- PHP XMLReader open()用法及代碼示例
- PHP XMLReader close()用法及代碼示例
- PHP XMLReader getAttributeNo()用法及代碼示例
- PHP XMLReader moveToNextAttribute()用法及代碼示例
- PHP XMLReader getAttributeNs()用法及代碼示例
- PHP XMLReader setParserProperty()用法及代碼示例
注:本文由純淨天空篩選整理自gurrrung大神的英文原創作品 PHP | XMLReader lookupNamespace() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。