Combining two documents through the DOM with ASP


Document 1

<entry><name>
<firstname>William</firstname>
<lastname>Clinton</lastname></name>
<address><line1>1600 Pennsylvania Avenue</line1>
<line2>White House</line2>
<city>Washington</city>
<state>DC</state><postalcode>20000
</postalcode><country>USA</country></address>
</entry>

Document 2

<?xml version="1.0"?>
<letter>
<entry />
<greetings>Dear Fool,</greetings>
<p>You have won a million, trillion dollars!!!!!  In laminated game 
money, that is.  Please contact us to collect your prize at +1 888 555 1212.  
Shipping and handling fees of up to ten thousand dollars may be required to 
collect your prize.</p>
<signoff>Hahahaha!</signoff>
<signature>the prize committee (we prys your money away from you!)</signature>
</letter>

ASP Code

<%@LANGUAGE=JavaScript%>
<%Response.ContentType="application/xml";
sourceFile=Server.MapPath("prizewin.xml");
var myDoc=Server.CreateObject("Microsoft.XMLDOM");
myDoc.async=false;
myDoc.load(sourceFile);
var rootNode=myDoc.documentElement;
var oldEntry=rootNode.firstChild ;

sourceFile=Server.MapPath("address.xml");
var mySubDoc=Server.CreateObject("Microsoft.XMLDOM");
mySubDoc.async=false;
mySubDoc.load(sourceFile);
var entry=mySubDoc.documentElement; 
rootNode.replaceChild(entry,oldEntry);
Response.write(myDoc.xml)
%>

Test it

<Origin Page   TOC

Copyright 2000 Simon St.Laurent