我只是想問一個問題。我如何在使用php的xml中插入新節點。我的XML文件(questions.xml)在下面給出通過PHP在XML文件中添加新節點
<?xml version="1.0" encoding="UTF-8"?>
<Quiz>
<topic text="Preparation for Exam">
<subtopic text="Science" />
<subtopic text="Maths" />
<subtopic text="english" />
</topic>
</Quiz>
我想添加一個新的「subtext」和「text」屬性,即「geography」。我如何使用PHP來做到這一點?預先感謝,但。 以及我的代碼是
<?php
$xmldoc = new DOMDocument();
$xmldoc->load('questions.xml');
$root = $xmldoc->firstChild;
$newElement = $xmldoc->createElement('subtopic');
$root->appendChild($newElement);
// $ newText = $ xmldoc->一個createTextNode( '地質'); // $ newElement-> appendChild($ newText);
$xmldoc->save('questions.xml');
?>
y這是我..沒有滿意的答覆。 。 – user2083529 2013-03-04 12:29:13
因爲你沒有想到的解釋,但你可以使用一段代碼。沒有理由再次提出同樣的問題。 – 2013-03-04 12:30:39
有一個原因..看到..我有一個有效的答覆後,再次發佈...所以有一個原因再次發佈。 – user2083529 2013-03-04 12:48:47