So my old xml is like this:
Code: Select all
<videos>
<item>
<question>Old question</question>
<answers>Old answers</answers>
<url>Old url</url>
<position>Old pos</position>
<country>Old Country</country>
<category>Old category</category>
</item>
<item>Code: Select all
$xdoc = new DomDocument;
$xdoc->Load($xmlPath);
$videos = $xdoc->getElementsByTagName('videos')->item(0);
$addItem = $xdoc ->createElement('item');
$addQuestion = $xdoc ->createElement('question', $Question);
$addAnswers = $xdoc ->createElement('answers', $Answers);
$addURL = $xdoc ->createElement('url', $umaURL);
$addPosition = $xdoc ->createElement('position', $Position);
$addCountry = $xdoc ->createElement('country', $country);
$addCategory = $xdoc ->createElement('category', $category);
$videos -> appendChild($addItem);
$addItem -> appendChild($addQuestion);
$addItem -> appendChild($addAnswers);
$addItem -> appendChild($addURL);
$addItem -> appendChild($addPosition);
$addItem -> appendChild($addCountry);
$addItem -> appendChild($addCategory);
$saveXML = $xdoc->save($xmlPath);
Code: Select all
<videos>
<item>
<question>New question</question>
<answers>New answers</answers>
<url>New url</url>
<position>New pos</position>
<country>New Country</country>
<category>New category</category>
</item>
<item>
<question>Old question</question>
<answers>Old answers</answers>
<url>Old url</url>
<position>Old pos</position>
<country>Old Country</country>
<category>Old category</category>
</item>
</videos>