Access an element's parent with PHP's SimpleXML?

前端 未结 3 1586
半阙折子戏
半阙折子戏 2020-12-09 09:30

I\'m iterating through a set of SimpleXML objects, and I can\'t figure out how to access each object\'s parent node. Here\'s what I want:

$divs = simplexml-         


        
3条回答
  •  生来不讨喜
    2020-12-09 10:07

    If memory serves, an xpath() call returns one or more SimpleXMLElements. If that's the case, then you may be able to use something like:

    $div->xpath( '..' );
    # or
    $div->xpath( 'parent::*' );
    

提交回复
热议问题