PHP DOMElement::getElementsByTagName - Anyway to get just the immediate matching children?
Posted
by rr
on Stack Overflow
See other posts from Stack Overflow
or by rr
Published on 2010-06-15T22:52:43Z
Indexed on
2010/06/15
23:02 UTC
Read the original article
Hit count: 302
Hi All, is there a way to retrieve only the immediate children found by a call to DOMElement::getElementsByTagName? For example, I have an XML document that has a category element. That category element has sub category elements (which have the same structure), like:
<category>
<id>1</id>
<name>Top Level Category Name</name>
<subCategory>
<id>2</id>
<name>Sub Category Name</name>
</subCategory>
...
</category>
If I have a DOMElement representing the top level category,
$topLevelCategoryElement->getElementsByTagName('id');
will return a list with the nodes for all 'id' elements, where I want just the one from the top level. Any way to do this outside of using XPath?
© Stack Overflow or respective owner