生成XML源代碼:
$dom = new DOMDocument();
if(!$dom)
{
printf("構造XML失敗!
");
return -3999;
}
if(FALSE == ($dom->load($filename)))
{
add_root();
if(FALSE
== ($dom->load($filename)))
{
return -3999;
}
}
//引用root根節點
$f_node =
$dom->getElementsByTagName($parent_node)->item(0);
if(!$f_node)
{
$root =
$dom->getElementsByTagName(root)->item(0);
//創建父節點
$f_node =
$dom->createElement($parent_node);
$f_node =
$root->appendChild($f_node);
}
//創建節點
$item_node =
$dom->createElement($node);
$item_node =
$f_node->appendChild($item_node);
$item_value =
$dom->createTextNode($value);
$item_node->appendChild($item_value);