The getElementsByTagNameNS method of DOMElement in PHP retrieves all elements that match a given namespaceURI and localName.
Example 1:
Suppose we have an XML document containing a set of book elements under a bookstore element. We want to retrieve all book elements that belong to the "http://example.org/books" namespace.
Code:
$doc = new DOMDocument(); $doc->load("books.xml");
foreach ($books as $book) { // do something with each book element }
This code loads the XML document, retrieves the bookstore element, and uses the getElementsByTagNameNS method to retrieve all book elements under the bookstore element that belong to the "http://example.org/books" namespace.
Example 2:
Suppose we have an XML document containing a set of car elements under a cars element. We want to retrieve all car elements that belong to the "http://example.org/cars" namespace.
foreach ($cars as $car) { // do something with each car element }
This code loads the XML document, retrieves the cars element, and uses the getElementsByTagNameNS method to retrieve all car elements under the cars element that belong to the "http://example.org/cars" namespace.
Package/Library:
This code uses the built-in DOMDocument class in PHP, which is part of the PHP Core package.
PHP DOMElement::getElementsByTagnameNS - 1 examples found. These are the top rated real world PHP examples of DOMElement::getElementsByTagnameNS extracted from open source projects. You can rate examples to help us improve the quality of examples.