PHP DOMDocument: insertBefore, nasıl çalışması için?

0 Cevap php

Ben belirli bir elementin önce, yeni bir düğüm elemanı yerleştirmek istiyorum. Ben başarı olmadan, bunun için InsertBefore kullanıyorum!

İşte kod,

<DIV id="maindiv">

<!-- I would like to place the new element here -->

<DIV id="child1">

    <IMG />

    <SPAN />

</DIV>

<DIV id="child2">

    <IMG />

    <SPAN />

</DIV>

//$div is a new div node element,
//The code I'm trying, is the following:

$maindiv->item(0)->parentNode->insertBefore( $div, $maindiv->item(0) ); 

//Obs: This code asctually places the new node, before maindiv
//$maindiv object(DOMNodeList)[5], from getElementsByTagName( 'div' )
//echo $maindiv->item(0)->nodeName gives 'div'
//echo $maindiv->item(0)->nodeValue gives the correct data on that div 'some random text'
//this code actuall places the new $div element, before <DIV id="maindiv>

http://pastie.org/1070788

Her türlü yardım takdir, teşekkür!

0 Cevap