DOMDocument::getElementsByTagNameNS

(PHP 5, PHP 7)

DOMDocument::getElementsByTagNameNS Searches for all elements with given tag name in specified namespace

说明

public DOMDocument::getElementsByTagNameNS ( string $namespaceURI , string $localName ) : DOMNodeList

Returns a DOMNodeList of all elements with a given local name and a namespace URI.

参数

namespaceURI

The namespace URI of the elements to match on. The special value * matches all namespaces.

localName

The local name of the elements to match on. The special value * matches all local names.

返回值

A new DOMNodeList object containing all the matched elements.

范例

Example #1 Get all the XInclude elements

<?php

$xml 
= <<<EOD
<?xml version="1.0" ?>
<chapter xmlns:xi="http://www.w3.org/2001/XInclude">
<title>Books of the other guy..</title>
<para>
 <xi:include href="book.xml">
  <xi:fallback>
   <error>xinclude: book.xml not found</error>
  </xi:fallback>
 </xi:include>
 <include>
  This is another namespace
 </include>
</para>
</chapter>
EOD;
$dom = new DOMDocument;

// load the XML string defined above
$dom->loadXML($xml);

foreach (
$dom->getElementsByTagNameNS('http://www.w3.org/2001/XInclude''*') as $element) {
    echo 
'local name: '$element->localName', prefix: '$element->prefix"\n";
}
?>

以上例程会输出:

local name: include, prefix: xi
local name: fallback, prefix: xi

参见

相关文章
php domdocument searches for an element with a certain idphp domdocument searches for all elements with given local tag namephp domdocument searches for all elements with given tag name in specified namespacephp domelement declares the attribute specified by local name and namespace uri to be of type idphp domnamednodemap retrieves a node specified by namephp domnamednodemap retrieves a node specified by local name and namespace uriphp vector returns the result of adding all given values to the vectorphp db++ 函数 free all tuple locks on given relationphp id3 函数 get all information stored in an id3 tagphp ingres 函数 get a cursor name for a given result resourcephp msession 函数 find all sessions with name and valuephp snmp 函数 return all objects including their respective object id within the specified onephp snmp 函数 return all objects including their respective object id within the specified onephp stream 函数 runs the equivalent of the select system call on the given arrays of streams with a timeout specified by tv sec and tv usecphp locale searches the language tag list for the best match to the languagephp sdo das xml 函数 creates sdo dataobject for a given namespace uri and type namephp solrclient deletes all documents matching the given queryphp swoole table count the rows in the table or count all the elements in the table if $mode = 1.php ziparchive revert all changes done to an entry at the given indexphp ziparchive revert all changes done to an entry with the given name
关注编程学问公众号