怎么用DOM创建a节点?

怎么用DOM创建a节点


人到中年有点甜
浏览 529回答 4
4回答

拉风的咖菲猫

假设你的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不了,就加了这句~

ITMISS

var kk = document.createElement("newNote");document.getElementById('top_img').appendChild(kk);
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JQuery