我想根据数据库记录创建 xml doc 我已经编码了这些行,但我不知道如何将父节点放入其中:
$dom = new DOMDocument("1.0");
//header("Content-Type: text/plain");
while ($row = mysql_fetch_row($dtrs)) {
//create sub toping..
$root = $dom->createElement("case");
$dom->appendChild($root);
// create child element
$caseno = $dom->createElement("caseno");
$root->appendChild($caseno);
// create text node
$caseno_text = $dom->createTextNode($row[0]);
$caseno->appendChild($caseno_text);
// create child element
$petname = $dom->createElement("petname");
$root->appendChild($petname);
// create text node
$pet_text = $dom->createTextNode($row[1]);
$petname->appendChild($pet_text);
// create child element
$resname = $dom->createElement("resname");
$root->appendChild($resname);
// create text node
$res_text = $dom->createTextNode($row[2]);
$resname->appendChild($res_text);
// create child element
$hearing = $dom->createElement("hearing");
$root->appendChild($hearing);
// create text node
$hear_text = $dom->createTextNode($row[3]);
$hearing->appendChild($hear_text);
// create child element
$status = $dom->createElement("status");
$root->appendChild($status);
// create text node
$status_text = $dom->createTextNode($row[4]);
$status->appendChild($status_text);
}
我得到这样的结果,我无法将节点放入其中
<?xml version="1.0"?> <case> <caseno>010301</caseno> <petname>ashiq</petname> <resname>state</resname> <hearing>8012-08-02</hearing> <status>P</status> </case> <caseno>010302</caseno> <petname>hussain</petname> <resname>state</resname> <hearing>8012-08-02</hearing> <status>P</status> </case>
实际上我想要这样的结果;
<?xml version="1.0"?> <stage> <case> <caseno>010301</caseno> <petname>ashiq</petname> <resname>state</resname> <hearing>8012-08-02</hearing> <status>P</status> </case> <caseno>010302</caseno> <petname>hussain</petname> <resname>state</resname> <hearing>8012-08-02</hearing> <status>P</status> </case> </stage>
请帮帮我。