<xml masterProduct="3949">
<product1 mainProduct="yes">
<color>Red</color>
<price>23.99</price>
<onHand>483948</onHand>
</product1>
<product2 productID="2222"></product2>
<product3 productID="3333"></product3>
</xml>
<%@ LANGUAGE=VBSCRIPT %>
<%Option Explicit%>
<%
Response.Buffer = True
Dim objXML, strPath, oRoot, x, strColor, strPrice
strPath = "[YOUR_PATH_TO_THE_XML_FILE]"
Set objXML = Server.CreateObject("Microsoft.XMLDOM")
objXML.async = False
objXML.load (Server.MapPath(strPath))
If objXML.parseError.errorCode <> 0 Then
Response.Write(objXML.parseError.reason)
Response.Write(objXML.parseError.errorCode)
End If
Set oRoot = objXML.selectSingleNode("//xml/product1")
for each x in oRoot.childNodes
Select Case x.baseName
case "color"
strColor = x.text
case "price"
strPrice = x.text
case else
end select
next
set objXML = nothing
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>ASP to read XML file Page</title>
</head>
<body>
<b>COLOUR:</b> <%=strColor%><br />
<b>PRICE:</b> <%=strPrice%>
</body>
</html>
沒有留言:
張貼留言