Generating XML through the DOM with ASP


ASP Script:

<%@LANGUAGE=JavaScript%>
<%Response.ContentType="application/xml";
var myDoc=Server.CreateObject("Microsoft.XMLDOM");
myDoc.async=false;
var entry=myDoc.createElement("entry");;
myDoc.documentElement=entry;

var nameNode=myDoc.createElement("name");
var firstNameNode=myDoc.createElement("firstname");
var firstNameText=myDoc.createTextNode(Request.Form.item("firstname"));
firstNameNode.appendChild(firstNameText);
var lastNameNode=myDoc.createElement("lastname");
var lastNameText=myDoc.createTextNode(Request.Form.item("lastname"));
lastNameNode.appendChild(lastNameText);
nameNode.appendChild(firstNameNode);
nameNode.appendChild(lastNameNode);
entry.appendChild(nameNode);
var addressNode=myDoc.createElement("address")
var line1Node=myDoc.createElement("line1")
var line1Text=myDoc.createTextNode(Request.Form.item("address1"));
line1Node.appendChild(line1Text);
addressNode.appendChild(line1Node);
var line2Node=myDoc.createElement("line2")
var line2Text=myDoc.createTextNode(Request.Form.item("address2"));
line2Node.appendChild(line2Text);
addressNode.appendChild(line2Node);

var cityNode=myDoc.createElement("city")
var cityText=myDoc.createTextNode(Request.Form.item("city"));
cityNode.appendChild(cityText);
addressNode.appendChild(cityNode);

var stateNode=myDoc.createElement("state")
var stateText=myDoc.createTextNode(Request.Form.item("state"));
stateNode.appendChild(stateText);
addressNode.appendChild(stateNode);

var postalNode=myDoc.createElement("postalcode")
var postalText=myDoc.createTextNode(Request.Form.item("postalcode"));
postalNode.appendChild(postalText);
addressNode.appendChild(postalNode);

var countryNode=myDoc.createElement("country")
var countryText=myDoc.createTextNode(Request.Form.item("country"));
countryNode.appendChild(countryText);
addressNode.appendChild(countryNode);

entry.appendChild(addressNode);

Response.write(myDoc.xml)
%>

<Origin Page   TOC

Copyright 2000 Simon St.Laurent