The XML DOM (Dynamic Object Model)


This example uses the XML DOM (XML Document Object Model) to render an HTML page to the client machine from an XML document generated by ASP, a server-side scripting language.

<% @LANGUAGE = VBScript %>
<% Option Explicit %>

<HTML>

<HEAD>
<TITLE>XML USING the DOM</TITLE>
</HEAD>

<BODY BGCOLOR="#FFFFFF">

<%
	Dim XMLDoc, rootNode, resort, item, i strTemperature
	Set XMLDoc = Server.CreateObject ("Microsoft.XMLDOM") Creates an instance of the Microsoft XML Document Object Model.
	XMLDoc.async = False
	XMLDoc.load (Server.MapPath("weatherForecast.xml"))
	Set rootNode = XMLDoc.documentELement This retrieves the root node of the XML document.

	Response.Write "<h1>Weather Report "
	Response.Write rootNode.attributes.getNamedItem ("date").text & "</h1>" & vbCrLf Retrieves the date data attribute.

	If rootNode.hasChildNodes () Then Test for the existence of city child elements.
		For Each city in rootNode.childNodes
			For Each item in city.childNodes
				If "name" = item.nodeName Then
					Response.Write "<b> & item.Text & "</b><BR>"
				ElseIf "temperature" = item.nodeName Then Identifies the node name.
					strTemperature = ""
					For i = 0 to item.childNodes.length - 1
						strTemperature = strTemperature & item.childNodes(i).text & "/"
					Next
					strTemperature = Left (strTemperature, Len (strTemperature) - 1) & " cm" & "<BR>" & vbCrLf
					Response.Write strTemperature
				End If
			Next
		Next
	End If
%>

</BODY>
</HTML>