PHP往XML中添加节点的方法_php技巧
程序员文章站
2022-04-18 14:16:35
...
本文实例讲述了PHP往XML中添加节点的方法。分享给大家供大家参考。具体方法如下:
J
J
J
Manager
National
1971-12-22
2. php代码
1. contacts.xml代码
复制代码 代码如下:
2. php代码
复制代码 代码如下:
$tel_node = null;
$doc = xmldocfile ('contacts.xml');
$contact_node = $doc->root ();
$kids = $contact_node->children ();
while ($node = array_shift ($kids)) {
if (($node->type == XML_ELEMENT_NODE) && ($node->tagname == 'personal')) {
$tel_node =& $node;
break;
}
}
if ($tel_node == null){
die ("Couldn't locate 'personal' node.");
}
$work_node = $tel_node->new_child ('work', '6666');
print ("
?>
$doc = xmldocfile ('contacts.xml');
$contact_node = $doc->root ();
$kids = $contact_node->children ();
while ($node = array_shift ($kids)) {
if (($node->type == XML_ELEMENT_NODE) && ($node->tagname == 'personal')) {
$tel_node =& $node;
break;
}
}
if ($tel_node == null){
die ("Couldn't locate 'personal' node.");
}
$work_node = $tel_node->new_child ('work', '6666');
print ("
\n");\n");
print (htmlspecialchars ($doc->dumpmem ()));
print ("
?>
希望本文所述对大家的php程序设计有所帮助。
上一篇: css折叠样式(2)――定义样式表
下一篇: inkscape--shape教程(译)