可能重複:
How is possible add child to the specific node節點添加到XML
我怎麼可以將節點添加到XML文件這樣的:
<users>
<user uid="1" name="Alvin" email="[email protected]"/>
</users>
例如PHP:
$xml_file = "example.xml";
// WRITING TO XML FILE
if(!empty($_GET['add'])){
$u_name = stripslashes($_POST['u_name']);
$u_email = stripslashes($_POST['u_email']);
// Generate new (appended) ID
foreach($xml as $user){
$last_id = $user->uid;
}
$id = $last_id+1;
// Add node
$x = $xml->addChild("user");
$x->addChild("uid",$id);
$x->addChild("name",$u_name);
$x->addChild("email",$u_email);
$xml->asXML($xml_file);
}
感謝您的幫助和/或建議
請使用搜索,例如看到這裏:[如何可能添加孩子到特定的節點](http://stackoverflow.com/questions/9706558/how-is-possible-add-child-to-the-specific-node) – hakre 2012-03-14 17:40:06
或者也許谷歌。搜索「用PHP添加節點到XML」返回近800萬條結果。 – Brian 2012-03-14 17:42:07