<adress> <persona id="3"> <firstname>Ziom</firstname> <inf>no information</inf> <nick>dead</nick> </persona> </adress>
i na przykład chce aby do wszystkich elementów zawierających wartość (firstname, inf, nick) dodać nowy element np:
<adress> <persona id="3"> <firstname> <nowyelement>Ziom</nowyelement> </firstname> <inf> <nowyelement>no information</nowyelement> </inf> <nick> <nowyelement>dead</nowyelement> </nick> </persona> </adress>
oto skrypt:
<?php function dodawnie( $dom ) { $dom = $dom->firstChild; { if( $dom->nodeType == XML_TEXT_NODE ) { { $form = $dom->appendChild( new DomElement('nowyelement', $dom->nodeValue ) ); } } if ($dom->hasChildNodes()) { dodawanie( $dom ); } $dom = $dom->nextSibling; } } $dom = new DOMDocument(); $dom->loadXml('plik.xml'); dodawanie( $dom ); ?>
bład wywala mi w $form = $dom->appendChild( new DomElement('nowyelement', $dom->nodeValue ) );
Co mam zrobić??