PHP DOMElement::getElementsByTagName - Anyway to get just the immediate matching children?

后端 未结 4 469
感动是毒
感动是毒 2020-12-16 03:08

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.

4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-16 03:51

    I don't use PHP, but if PHP actually implements the DOM API as specified the W3C, there is required to be a childNodes property on any Node object. You should be able to iterate over all of the direct children and test their tag name to see if they're the one you're looking for. Depending on what your tree looks like, this may be slower than getting all the elements by tag name and testing their tree position, or it may be significantly faster.

提交回复
热议问题