An example of generating and using XML on the client

Source: Internet
Author: User
Tags add date define object client
xml| Client

This is an example of generating and using XML on the client, the main purpose of which is to refresh the page to handle complex data on the client, consisting of two files. We can take a look at it and put forward valuable suggestions. Note: Change the savexml.asp path to genxml.html physical path when used

-genxml.html-
<!--
*******
' * Author HARDVB
' * Support: web@webjx.com
' * Date created:2004/6/18 Merry Chrismas Day
' * Date Modified:
' * Function:genrate XML tree and show in Client
'********
-->
<title>
Item Information
</title>

<body>
<br>
<div Id=additem name=additem></div> <!--the div use for add item-->
<form name=formitem action= "processform.asp" method= "POST" >
<table width= "60%" border= "2" bordercolor= "Orange" cellspacing= "1" cellpadding= "1" >
<tr>
&LT;TD Colspan=2></tr>
<tr>
<td>item name:</td>
<td><input type= "text" name= "ItemName" ></td>
<tr>
<tr>
<td>mount: </td>
<td> <input type= "text" name= "Mount" ></td>
</tr>
<tr>
<td> Spec: </td>
<td> <input type= "text" name= "Spec" ></td>
</tr>
<tr>
<td> price:</td>
<td><input type= "text" name= "Price" ></td>
</tr>
<tr>
&LT;TD Align=center colspan=2>
<input type= "button" id= "Btnsub" name= "Btnsub" value= "ADD" >
<input type= "button" id= "Btndel" name= "Btndel" value= "Del" >
Del No: <input type= "text" size=3 name= "Delno" >
<input type= "button" size=3 value= "ReList all Item": >
</td>
</tr>


</TABLE>
</form>
<input type= "button" id= "Lookxml" name= "Lookxml" value= "Look XML" ><br>
</body>


<script language= "JavaScript" >
file://-----Global var define-------
var itemno=0; File://how Many Items born and die
var objdom = new ActiveXObject ("MSXML". DOMDocument "); File://define a DOM object
Objdom.async=false;
var objroot = objdom.createelement ("EPR"); File://create the root "EPR"
Objdom.appendchild (Objroot)
var XmlHTTP = new ActiveXObject ("Microsoft.XMLHTTP"); File://create the XMLHTTP object for Save XML without Refrsh Page


file://-------Add a new node----------
function Add ()
{
itemno++;
var itemsec=document.all.additem.children.length; How many alive Items
itemsec++;


var objfield = objdom.createelement ("Item") file://create node "Epr-->item"
ObjDom.documentElement.appendChild (Objfield);


Curnode=objdom.documentelement.lastchild; File://look for last added node
var namednodemap =curnode.attributes;


var Objattid = Objdom.createattribute ("ItemNo"); File://add attribute "ItemNo"
Objattid.text =itemno
Namednodemap.setnameditem (Objattid);


var Objattid = objdom.createelement ("Name") file://create node "Epr-->item-->name"
Objattid.text=document.formitem.itemname.value
Curnode.appendchild (Objattid)
Document.formitem.itemname.value= "";


var Objattid = objdom.createelement ("Mount") file://create node "Epr-->item-->mount"
Objattid.text=document.formitem.mount.value
Curnode.appendchild (Objattid)
Document.formitem.mount.value= ""


var Objattid = objdom.createelement ("Spec") file://create node "Epr-->item-->spec"
Objattid.text=document.formitem.spec.value
Curnode.appendchild (Objattid)
Document.formitem.spec.value= ""


var Objattid = objdom.createelement ("price") file://create node "Epr-->item-->price"
Objattid.text=document.formitem.price.value
Curnode.appendchild (Objattid)
Document.formitem.price.value= ""


SaveXML (); File://save in Server with ASP


AddItem (); File://Show in DIV
}


file://-----------Del Node-------------
function Del (Delno)
{
var cond
var itno=delno-1
Cond= "item[" +itno+ "]";
var delnode=objdom.documentelement.selectsinglenode (Cond) file://choose node to Del
var del=objroot.removechild (Delnode)
SaveXML (); File://save in Server with ASP
Delitem (Delno); File://Del in DIV
}


file://----------Save XML----------------
function SaveXML ()
{
Xmlhttp.open ("POST", "savexml.asp", false);
Xmlhttp.send (Objdom);
if (XmlHTTP.responseText.indexOf ("Error:")!=-1)
{
alert (Xmlhttp.responsetext);
}
}


file://---------Add Item--------------------
function AddItem ()
{
var itemsec=document.all.additem.children.length;
itemsec++;
var Additem=document.all.additem;
var onewnode = document.createelement ("DIV");
Additem.appendchild (Onewnode);
Onewnode.innerhtml= "<Table><tr><td> itemsec" + itemsec + "ItemNo" +itemno+ "</td></tr> </Table> ";
}


file://---------Del Item--------------------
function Delitem (ITNO)
{var Itnum=itno
var Additem=document.all.additem;
var ochild=additem.children (ItNum-1);
Additem.removechild (Ochild);
}


file://---------List Item--------------------


function ListItem ()
{
var Additem=document.all.additem;
var itemlist=0;
var Onewnode;
Additem.innerhtml= ""; File://clear DIV


for (x=0;x<objdom.documentelement.childnodes.length;x++)
{
itemlist=x+1; File://get List NO
Itemnode=objdom.documentelement.childnodes (x) file://chose cucrry node
Itemname=itemnode.selectsinglenode ("Name");
Itemmount=itemnode.selectsinglenode ("Mount");
Itemspec=itemnode.selectsinglenode ("Spec");
Itemprice=itemnode.selectsinglenode ("Price");


Onewnode = document.createelement ("DIV");
Additem.appendchild (Onewnode);
Onewnode.innerhtml= "<table width= ' 60% ' border= ' 1 ' bordercolor= ' green ' cellspacing= ' 1 ' cellpadding= ' 1 ' ><tr ><TD colspan=2 align=center> ItemNo "+itemlist+" </td></tr><tr><td WIDTH= ' 30% ' >name : </td><td width= ' 30% ' > "+itemname.text+" </td></tr><tr><td WIDTH= ' 30% ' >Item Mount: </td><td width= ' 30% ' > ' +itemmount.text+ ' </td></tr><tr><td WIDTH= ' 30% ' > Spec: </td><td width= ' 30% ' > ' +itemspec.text+ ' </td></tr><tr><td WIDTH= ' 30% ' > Price: </td><td width= ' 30% ' > ' +itemprice.text+ ' </td></tr></Table> ';
}
}

</script>


------------savexml.asp-----------------
<%@ Language=vbscript%>
<%
Response.expires=-1
Dim Xmlrec
Set Xmlrec=server. CreateObject ("Microsoft.XMLDOM")
Xmlrec.async=false
Xmlrec.load (Request)
Xmlrec.save "C:\EPR.xml" '//please change Path with your IIS Path
' Response.Write GetPath () & "\epr.xml"
%>



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.