Muszę dodać nowy element w miejscu jego zawartości. Czyli mamy przykładowy plik xml:
  1. <adress>
  2. <persona id="3">
  3. <firstname>Ziom</firstname>
  4. <inf>no information</inf>
  5. <nick>dead</nick>
  6. </persona>
  7. </adress>

i na przykład chce aby do wszystkich elementów zawierających wartość (firstname, inf, nick) dodać nowy element np:
  1. <adress>
  2.      <persona id="3">
  3.            <firstname>
  4.                  <nowyelement>Ziom</nowyelement>
  5.            </firstname>
  6.            <inf>
  7.                  <nowyelement>no information</nowyelement>
  8.            </inf>
  9.            <nick>
  10.                  <nowyelement>dead</nowyelement>
  11.            </nick>
  12.      </persona>
  13. </adress>

oto skrypt:
  1. <?php
  2.  
  3. function dodawnie( $dom )
  4. {
  5.  $dom = $dom->firstChild;
  6.  while (! is_null( $dom ) )
  7.  {
  8. if( $dom->nodeType == XML_TEXT_NODE )
  9. {
  10. if (trim( $dom->nodeValue ) != '')
  11. {
  12. $form = $dom->appendChild( new DomElement('nowyelement', $dom->nodeValue ) );
  13. }
  14. }
  15. if ($dom->hasChildNodes())
  16. {
  17.  dodawanie( $dom );
  18. }
  19. $dom = $dom->nextSibling;
  20.  }
  21. }
  22.  
  23. $dom = new DOMDocument();
  24. $dom->loadXml('plik.xml');
  25. dodawanie( $dom );
  26. print $dom->saveXml();
  27.  
  28.  
  29. ?>


bład wywala mi w $form = $dom->appendChild( new DomElement('nowyelement', $dom->nodeValue ) );
Co mam zrobić??