Classic asp example xml parser


Classic asp example xml parser

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
		<title>Richard Test</title>
		<meta name="author" content="">
		<meta name="description" content="">
		<meta name="keywords" content="">
		body {background-color: black;color:rgb(17, 216, 17);font-family: courier;font-size:8pt}a {color:     #68FFC8;}a:hover {color: #68dcff;}a:active{color: white;}a:visited{color:#46dc44;}

	<body leftmargin=0 marginwidth=0 topmargin=0 marginheight=0 bgcolor="#ffffff">

		dim xmlText:xmlText=""
		if false then
			Response.Write("readservice start<br>")
			Set getPage = Server.CreateObject("Microsoft.XMLHTTP" )
			getPage.Open "POST", "http://url-to-xmlgen/dataTest_3.asp", false
			getPage.SetRequestHeader "Content-Type", "text/xml; charset=utf-8"
			getPage.Send "some data here..."
			xmlText = getPage.responseText
			Set getPage = Nothing
			Response.Write("readservice end<br>")
		end if
		ReadData(xmlText)  ''getPage.responseText

		Function ReadData(xmlString)
			Response.Write("ReadData start<br>")
			Dim xmldoc 
			'Use the MSXML 4.0 Version dependent PROGID 
			'MSXML2.DOMDocument.4.0 if you wish to create
			'an instance of the MSXML 4.0 DOMDocument object
			Set xmldoc = Server.CreateObject("MSXML2.DOMDocument") 

			Response.Write("loadxml start<br>")
			' for calling local XML
			xmldoc.Load Server.MapPath("data.xml")  'this is used for reading an xml text file
			'xmldoc.LoadXML xmlString  'this is used for reading an xml string

			Response.Write("loadxml end<br>")
			if xmldoc.parseerror.errorcode <> 0 then 
				Response.Write "Error loading XML Document :" & "<BR>"
				Response.Write "----------------------------" & "<BR>"
				Response.Write "Error Code : " & xmldoc.parseerror.errorcode & "<BR>"
				Response.Write "Reason : " & xmldoc.parseerror.reason & "<BR>"
			End If

			dim supplierNodes: set supplierNodes = xmldoc.selectNodes("//GetAllSuppliersResponse/Suppliers/Supplier")
			Response.Write("num suppliers ["&supplierNodes.length&"]<br>")
			dim scan:scan=0
			dim baseNode
			for scan=1 to supplierNodes.length-1
				set baseNode = 		supplierNodes(scan)
				if not (baseNode Is Nothing) then
					response.Write("SupplierCode [" &  baseNode.selectSingleNode("SupplierCode").text &"]<br>")
					response.Write("SupplierCode [" &  baseNode.selectSingleNode("CurrencyCode").text &"]<br>")
					response.Write("ContractEmail [" & baseNode.selectSingleNode("ContractEmail").text &"]<br>")

					response.Write(" ---- FirstName           [" & baseNode.selectSingleNode("SubmitBy/FirstName").text &"]<br>")
					response.Write(" ---- LastName            [" & baseNode.selectSingleNode("SubmitBy/LastName").text &"]<br>")
					response.Write(" ---- Position            [" & baseNode.selectSingleNode("SubmitBy/Position").text &"]<br>")
					response.Write(" ---- Company             [" & baseNode.selectSingleNode("SubmitBy/Company").text &"]<br>")
					response.Write(" ---- SubmissionDatetime ["  & baseNode.selectSingleNode("SubmitBy/SubmissionDatetime").text &"]<br>")
					response.Write(" ---- FileName            [" & baseNode.selectSingleNode("SubmitBy/FileName").text &"]<br>")
					response.Write(" basenode missing<br>")
				end if
			Response.Write("ReadData end<br>")

		End Function
		Function GetXML(URL)
		  Dim oXMLHttp
		  Dim oADORec
		  Dim sXML
		  'Dim URL
		  Set oXMLHttp = Server.CreateObject("MSXML2.ServerXMLHTTP") "GET", URL, false
		  oXMLHttp.send()                   ' Send the request.
		  if oXMLHttp.status = 200 Then 
		    sXML = oXMLHttp.responseText   ' Retrieve from serverB.
		    if ucase(trim(mid(sXML,1,6))) <> "XMLERR" then
		      GetXML = sXML
		      GetXML = "Err: " & Trim(mid(sXML,7,40))
				end if
		    GetXML = "Could not get XML data."
		  end if
		  set oXMLHttp = nothing
		end function



Leave a Comment