码迷,mamicode.com
首页 > Web开发 > 详细

php添加xml节点

时间:2016-03-07 18:33:03      阅读:162      评论:0      收藏:0      [点我收藏+]

标签:

光写些重要的部分

xml:

<action name="fabiao">
js(‘fabiao( get(ath),get(atv))‘);
</action>

html:

<script>
function fabiao(x,y){

var dmtext = document.getElementsByName("pinglun")[0].value;
location.href="updateXML.php?cont="+dmtext+"&x="+x+"&y="+y;
}
</script>

php:

//添加xml节点
<?php
$cont = $_GET[‘cont‘];
$ctime = time();
mysql_connect("127.0.0.1", "root", "root");
mysql_select_db("pinglun");
mysql_query("set names ‘utf8‘");
$sql_insert = "insert into think_comment (wecha_id,content,createtime) values(‘123456‘,‘$cont‘,‘$ctime‘)";
$res_insert = mysql_query($sql_insert);

$dom = new DOMDocument();
$dom->load("tour.xml");

$data_array = array(
array(
‘hotspot‘ => ‘‘,
)
);
// 属性数组
$attribute_array = array(
‘hotspot‘ => array(
‘name‘ => ‘name1‘, //此处为wecha_id
‘style‘ => ‘styleoftext222‘,
‘keep‘ => ‘false‘,
‘ath‘ => $_GET[‘x‘],
‘atv‘ => $_GET[‘y‘],
‘html‘ => $_GET[‘cont‘],
‘ondown‘ => ‘draghotspot();‘,
‘seid‘=>mysql_insert_id(),
)
);

//iconv("GB2312//IGNORE","UTF-8" , $attribute_array );
// 创建根节点
$item = $dom->getElementsByTagName(‘scene‘)->item(0);
foreach ($data_array as $data) {

create_item($dom, $item, $data, $attribute_array);
}
$dom->save(‘tour.xml‘);
echo"<script>history.back(-1);</script>";

function create_item($dom, $item, $data, $attribute) {
if (is_array($data)) {
foreach ($data as $key => $val) {
// 创建元素
$$key = $dom->createElement($key);
$item->appendchild($$key);
// 创建元素值
$text = $dom->createTextNode($val);
$$key->appendchild($text);
if (isset($attribute[$key])) {
// 如果此字段存在相关属性需要设置
foreach ($attribute[$key] as $akey => $row) {
// 创建属性节点
$$akey = $dom->createAttribute($akey);
$$key->appendchild($$akey);
// 创建属性值节点
$aval = $dom->createTextNode($row);
$$akey->appendChild($aval);
}
} // end if
}
} // end if
}

// end function

php添加xml节点

标签:

原文地址:http://www.cnblogs.com/yangchong/p/5251150.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!