4 回答
TA贡献1995条经验 获得超2个赞
假设你的xml为stu.xml
---------------那么--------------
$doc = new DOMDocument();
$doc->load( 'stu.xml' );
$students = $doc->getElementsByTagName( "xuesheng" );
foreach($students as $stu){
$yuwen = $stu->getElementsByTagName( "yuwen" )->item(0)->nodeValue;
$shuxue = $stu->getElementsByTagName( "shuxue" )->item(0)->nodeValue;
$yingyu = $stu->getElementsByTagName( "yingyu" )->item(0)->nodeValue;
$zongfen = $stu->getElementsByTagName( "zongfen" )->item(0)->nodeValue;
if($zongfen){
echo "节点已经存在了,不再添加!";
continue;
}
$zongfen = $yuwen+$shuxue+$yingyu;
$newNode = $doc->createElement("zongfen",$zongfen);
$stu->appendChild($newNode);
}
echo $result = $doc->saveXML();
file_put_contents("stu.xml",$result); //这句其实是不需要加上的- - 但是我也不晓得为什么save不了,就加了这句~
TA贡献1871条经验 获得超8个赞
var kk = document.createElement("newNote");
document.getElementById('top_img').appendChild(kk);
- 4 回答
- 0 关注
- 528 浏览
添加回答
举报