Remove a child with a specific attribute, in SimpleXML for PHP

后端 未结 17 2407
星月不相逢
星月不相逢 2020-11-22 02:50

I have several identical elements with different attributes that I\'m accessing with SimpleXML:


    
    

        
17条回答
  •  攒了一身酷
    2020-11-22 02:55

    With FluidXML you can use XPath to select the elements to remove.

    $doc = fluidify($doc);
    
    $doc->remove('//*[@id="A12"]');
    

    https://github.com/servo-php/fluidxml


    The XPath //*[@id="A12"] means:

    • in any point of the document (//)
    • every node (*)
    • with the attribute id equal to A12 ([@id="A12"]).

提交回复
热议问题