Jak w tytule ma plik XML za pomocą DOM-a próbuje dodać do istniejącej bazy w XML nowe rekordy, ale za każdym razem kiedy dodaje usuwa poprzednie. W pliku XML mam juz element główny baza
Kod
<?xml version="1.0" encoding="UTF-8"?>
<baza xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="towar.xsd">
</baza>
<baza xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="towar.xsd">
</baza>
I chce teraz dodawać element potomny towar
Kod
<?
$xml = new DOMDocument('1.0', 'utf-8');
$xsl = new DOMDocument();
$xml->formatOutput = true;
$xml->preserveWhiteSpace = false;
$xml->load("baza.xml");
$xsl->load("towar.xsl");
$procesor = new XSLTprocessor();
$procesor->importStylesheet($xsl);
echo $procesor->transformToXML($xml);
$towar = $xml->createElement('towar');
$newtowar = $xml->appendChild($towar);
$newtowar->setAttribute("id","2");
$nazwa = $xml->createElement('nazwa');
$towar->appendChild($nazwa);
$waznosc = $xml->createElement('waznosc','12.04.2009');
$towar->appendChild($waznosc);
$rodzaj = $xml->createElement('rodzaj','pieczywo');
$towar->appendChild($rodzaj);
$info = $xml->createElement('info','cos tam');
$towar->appendChild($info);
$xml->saveXML();
?>
$xml = new DOMDocument('1.0', 'utf-8');
$xsl = new DOMDocument();
$xml->formatOutput = true;
$xml->preserveWhiteSpace = false;
$xml->load("baza.xml");
$xsl->load("towar.xsl");
$procesor = new XSLTprocessor();
$procesor->importStylesheet($xsl);
echo $procesor->transformToXML($xml);
$towar = $xml->createElement('towar');
$newtowar = $xml->appendChild($towar);
$newtowar->setAttribute("id","2");
$nazwa = $xml->createElement('nazwa');
$towar->appendChild($nazwa);
$waznosc = $xml->createElement('waznosc','12.04.2009');
$towar->appendChild($waznosc);
$rodzaj = $xml->createElement('rodzaj','pieczywo');
$towar->appendChild($rodzaj);
$info = $xml->createElement('info','cos tam');
$towar->appendChild($info);
$xml->saveXML();
?>
Jak zrobić żeby dodawało pod elementem głownym <baza>(który jest wpisany na stałe w pliku xml) dodawało za każdym razem nowy element potomny <towar> i żeby po zmienieniu danych dopisywało kolejny element <towar> a nie za każdym razem usuwało i wpisywało nowy.
Dziękuje za wszelką pomoc bo już trochę nad tym siedze.
Pozdrwiam