Extracting Information 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:

<entries><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>

<entry><name><firstname>George</firstname><lastname>Bush</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>
<entry><name><firstname>Ronald</firstname><lastname>Reagan</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>
</entries>

ASP Code:

<%@LANGUAGE=JavaScript%>
<%Response.ContentType="application/xml";%>
<names><%
fileName=Request.QueryString("address");
sourceFile=Server.MapPath(fileName);
var myDoc=Server.CreateObject("Microsoft.XMLDOM");
myDoc.async=false;
myDoc.load(sourceFile);var entryCollection=myDoc.getElementsByTagName("lastname");
entries=entryCollection.length;

for (i=0; i<entries; i++) {
var inspection=entryCollection.item(i);
%>Last name: <%
var lastname=inspection.nodeName;

Response.Write(inspection.xml);
%>
<% } %>
</names>

<Origin Page   TOC

Copyright 2000 Simon St.Laurent