我已閱讀了許多有關此主題的相關問題,似乎無法找到一個突出顯示將其保存爲2個單獨的XML文件的問題。更新現有文件時創建新的XML文件
我在上傳電子書時創建了一個新的XML文件。對於這個例子,它將被保存在「new_file.xml」中。同時,我需要將新信息(本示例中爲<product>
)添加到名爲「full_collection_file.xml」的完整集合文件中,並將該文件更新。因此,每次上傳新電子書時,「full_collection_file.xml」都會添加一個新的<product>
。
下面是簡單的「new_file.xml」目前的結構:
$xml = new DomDocument('1.0', 'UTF-8');
$message = $xml->createElement('ONIXMessage');
$release = $xml->createAttribute('release');
$release->value = '3.0';
$message->appendChild($release);
$header = $xml->createElement('Header');
$FromCompany = $xml->createElement('FromCompany','My Company');
$header->appendChild($FromCompany);
$FromEmail = $xml->createElement('FromEmail','[email protected]');
$header->appendChild($FromEmail);
$SentDate = $xml->createElement('SentDate','201408181805');
$header->appendChild($SentDate);
$message->appendChild($header);
$product = $xml->createElement('Product');
$RecordReference = $xml->createElement('RecordReference','B00BBE4BFE');
$product->appendChild($RecordReference);
$NotificationType = $xml->createElement('NotificationType','03');
$product->appendChild($NotificationType);
$message->appendChild($product);
$xml->appendChild($message);
$xml->save('new_file.xml');
也能正常工作創建第一個XML文件(「new_file.xml」),但不管如何我嘗試做內同樣的地區,我似乎無法正確加載和更新「full_collection_file.xml」。我應該試圖單獨完成這兩件事情,而不是同時完成?似乎多餘,但我希望你可以有2個DomDocument文件同時進行。
@Jongware明白了。謝謝。 – 2014-09-29 16:16:39