如何通过PHP Parsing在XML文件中插入数据HTML表单数据 [英] How To Insert Data HTML form Data in XML file through PHP Parsing

查看:56
本文介绍了如何通过PHP Parsing在XML文件中插入数据HTML表单数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

index.html的代码



code for index.html

<html>
<body> 
 <table align="center" border="0" cellpadding="1" cellspacing="1" style="width: 500px;">
 <form name="form" action="form.php" method="post">
	<tbody>
		<tr>
			<td>ID:</td>
			<td><input type="text" id="id_code" name= "id_code" /></td>
		</tr><br/>
		<tr>
			<td>VALUE:</td>
			<td><input type="text" id="id_value" name= "id_value"/></td>
		</tr><br/>
		<tr align="center">
			<td><input name="submit" type = "button" onClick = "getData('form.php', id_code.value,id_value.value)" value = "Add Data" />
			<button type="reset" value="Reset">Reset</button></td>
		</tr><br/>
	</tbody>
	</form>
</table>
</body>
</html>







表格代码.js




code for form.js

<script src="jquery-1.4.2.min">
var xhr = createRequest();
function getData(dataSource,id_code,id_value) {
if(xhr) {
var obj = document.getElementById(divID);
var requestbody ="idd="+encodeURIComponent(id_code)+"&itd="+encodeURIComponent(id_value);
xhr.open("POST", dataSource, true);
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.onreadystatechange = function() {
if (xhr.readyState == 4 && xhr.status == 200) {
obj.innerHTML = xhr.responseText;
} // end if
} // end anonymous call-back function
xhr.send(requestbody);
} // end if
} // end function getData()





form.php的代码< br $> b $ b



code for form.php

 <?php
 
 
 <script type="text/javascript" src="form.js" src="jquery-1.4.2.min"></script>
 
$post_id_code= $_POST["idd"];
$post_id_value = substr($_POST["itd"], 0,10);

$xml = new DomDocument();
$xml->load("form.xml");

$xml->formatOutput = true;   

$global = $xml->documentElement;
$global = $xml->firstChild;     
$item = $xml->createElement('item');   
$global->appendChild($item); 
$id_code = $xml->createElement('id_code');
$idvalue = $xml->createElement('idvalue'); 
$item->appendChild( $id );
$id_code->nodeValue = $post_id_code;
$item->appendChild( $idvalue );
$idvalue->nodeValue = $post_id_value;

$xml->save("form.xml");

?>





我希望我的form.xml文件类似于





I want my form.xml file to be like

<?xml version="1.0" encoding="UTF-8"?>
<global>
 <item>
   <id="12" value="numbering">
   <id="123" value="counting">
 </item>
</global>

推荐答案

post_id_code =
post_id_code=


_POST [idd ];
_POST["idd"];


post_id_value = substr(
post_id_value = substr(


这篇关于如何通过PHP Parsing在XML文件中插入数据HTML表单数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆