ITsolutionWizard
asked on
classic asp xml
I have below xml structure. and want to read
1. the xml in classic asp,
2. and list the productInfo where ModelName = 'USB'
Thanks
1. the xml in classic asp,
2. and list the productInfo where ModelName = 'USB'
Thanks
<?xml version="1.0"?>
<SOAP:Envelope xmlns:SOAP="urn:schemas-xmlsoap-org:soap.v1"><SOAP:Header/>
<SOAP:Body>
<m:RetrieveResponse xmlns:m="urn:jbase/soap:RetrieveData">
<RetrieveResult>
<CompanyNumber>002</CompanyNumber>
<Status>Completed</Status>
<ProductInfo>
<ModelNo>KDC</ModelNo>
<ModelName>USB</ModelName>
<ListPrice>9.00</ListPrice>
<AMDPrice/><NetPrice/>
</ProductInfo>
<ProductInfo>
<ModelNo>ABC</ModelNo>
<ModelName>USBC</ModelName>
<ListPrice>8.00</ListPrice>
<AMDPrice/><NetPrice/>
</ProductInfo>
</RetrieveResult>
</m:RetrieveResponse>
</SOAP:Body>
</SOAP:Envelope>
Here are some more examples this one uses a payment gateway http:Q_28459564.html#a40146520 and this one you can run on your own to get the weather http:Q_28459564.html#a40147694
ASKER
Actually, I have actual physical xml file saved into the hard drive. So we don't have to create parameter to hold the xml string. Your example does not work the way i mentioned...
Did you actually code it or just copy? What I provided was an unfinished sample.
I will just repost my weather sample
Once you have coded the soap xml you have to use xmlhttppost to send a get or post. Where I have strURL you would replace with theXML or whatever variable you used.
<%
MyWeatherKey = request.form("api_key")
' 1) TO PREVENT UNAUTHORIZED USE, USE A PASSWORD OR KEY
' MY "BACKDOOR" IS A QUERYSTRING SO I CAN TEST DIRECTLY
if MyWeatherKey="abc123" or request("test")="abc123" then
'http://www.weather.gov/xml/current_obs/seek.php?state=il&Find=Find
' TO SEE THE OUTPUT, SURF TO THE URL
strUrl="http://w1.weather.gov/xml/current_obs/KORD.xml"
' 2) CALL THE WEBSERVICE VIA GET USING XMLHTTP
Set xmlHttp = Server.CreateObject("MSXML2.ServerXMLHTTP.3.0")
xmlHttp.Open "GET", strUrl, False
xmlHttp.setRequestHeader "User-Agent", "asp httprequest"
xmlHttp.setRequestHeader "content-type", "application/x-www-form-urlencoded"
xmlHttp.Send
getHTML = xmlHttp.responseText
' 3) THE RESPONSE IS NOW IN THE VARIABLE getHTML
' response.write getHTML will show the actual output
' 4) READ THE XML OUTPUT TO VARIABLES
Set objReturn = CreateObject("MSXML2.DOMDocument")
objReturn.LoadXml xmlHttp.responseText
if objReturn.getElementsByTagName("weather").length>0 then
weather =objReturn.getElementsByTagName("weather").Item(0).Text
else
weather=""
end if
if objReturn.getElementsByTagName("temp_f").length>0 then
temp_f=objReturn.getElementsByTagName("temp_f").Item(0).Text
else
temp_f=""
end if
if objReturn.getElementsByTagName("temp_c").length>0 then
temp_c=objReturn.getElementsByTagName("temp_c").Item(0).Text
else
temp_c=""
end if
if objReturn.getElementsByTagName("windchill_f").length>0 then
windchill_f =objReturn.getElementsByTagName("windchill_f").Item(0).Text
else
windchill_f=""
end if
if objReturn.getElementsByTagName("relative_humidity").length>0 then
relative_humidity=objReturn.getElementsByTagName("relative_humidity").Item(0).Text
else
relative_humidity=""
end if
if objReturn.getElementsByTagName("wind_string").length>0 then
wind_string=objReturn.getElementsByTagName("wind_string").Item(0).Text
else
wind_string=""
end if
if objReturn.getElementsByTagName("wind_dir").length>0 then
wind_dir =objReturn.getElementsByTagName("wind_dir").Item(0).Text
else
wind_dir=""
end if
if objReturn.getElementsByTagName("wind_degrees").length>0 then
wind_degrees=objReturn.getElementsByTagName("wind_degrees").Item(0).Text
else
wind_degrees=""
end if
if objReturn.getElementsByTagName("wind_mph").length>0 then
wind_mph=objReturn.getElementsByTagName("wind_mph").Item(0).Text
else
wind_mph=""
end if
if objReturn.getElementsByTagName("pressure_mb").length>0 then
pressure_mb=objReturn.getElementsByTagName("pressure_mb").Item(0).Text
else
pressure_mb=""
end if
if objReturn.getElementsByTagName("wind_string").length>0 then
pressure_in=objReturn.getElementsByTagName("pressure_in").Item(0).Text
else
pressure_in=""
end if
if objReturn.getElementsByTagName("dewpoint_f").length>0 then
dewpoint_f=objReturn.getElementsByTagName("dewpoint_f").Item(0).Text
else
dewpoint_f=""
end if
if objReturn.getElementsByTagName("dewpoint_c").length>0 then
dewpoint_c=objReturn.getElementsByTagName("dewpoint_c").Item(0).Text
else
dewpoint_c=""
end if
if objReturn.getElementsByTagName("visibility_mi").length>0 then
visibility_mi=objReturn.getElementsByTagName("visibility_mi").Item(0).Text
else
visibility_mi=""
end if
if objReturn.getElementsByTagName("icon_url_name").length>0 then
icon_url_name=objReturn.getElementsByTagName("icon_url_name").Item(0).Text
else
icon_url_name=""
end if
if objReturn.getElementsByTagName("station_id").length>0 then
station_id=objReturn.getElementsByTagName("station_id").Item(0).Text
else
station_id=""
end if
if objReturn.getElementsByTagName("latitude").length>0 then
latitude=objReturn.getElementsByTagName("latitude").Item(0).Text
else
latitude=""
end if
if objReturn.getElementsByTagName("longitude").length>0 then
longitude =objReturn.getElementsByTagName("longitude").Item(0).Text
else
longitude=""
end if
if objReturn.getElementsByTagName("observation_time").length>0 then
observation_time=objReturn.getElementsByTagName("observation_time").Item(0).Text
else
observation_ti=""
end if
if objReturn.getElementsByTagName("observation_time_rfc822").length>0 then
observation_time_rfc822 =objReturn.getElementsByTagName("observation_time_rfc822").Item(0).Text
else
observation_time_rfc82=""
end if
xmlHttp.abort()
set xmlHttp = Nothing
' 5) CREATE HTML TO DISPLAY
htmlOutPut = "<div id='weather'>"
htmlOutPut = htmlOutPut & "<div class='temp'>Temp: "&temp_f&"</div>"
htmlOutPut = htmlOutPut & "<div class='wind'>Wind: "&wind_mph&"</div>"
htmlOutPut = htmlOutPut & "<div class='forcast'>Current Weather: "&weather&"</div>"
htmlOutPut = htmlOutPut & "</div>"
response.write htmlOutPut
end if '
%>
Once you have coded the soap xml you have to use xmlhttppost to send a get or post. Where I have strURL you would replace with theXML or whatever variable you used.
Set xmlHttp = Server.CreateObject("MSXML2.ServerXMLHTTP.3.0")
xmlHttp.Open "GET", strUrl, False
xmlHttp.setRequestHeader "User-Agent", "asp httprequest"
xmlHttp.setRequestHeader "content-type", "application/x-www-form-urlencoded"
xmlHttp.Send
getHTML = xmlHttp.responseText
At the end to test if you have output, you can simply response.write getHTML
From there it is a matter of parsing your output.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
work.
one more if you have time
https://www.experts-exchange.com/questions/28465309/classic-asp-json-xml.html
one more if you have time
https://www.experts-exchange.com/questions/28465309/classic-asp-json-xml.html
You have to start by converting all your xml to a variable.
Open in new window
Notice that when building the xml, any double quotes inside are changed to single quotes. This is very important.If you need to add your own variable. You can covert this line
Open in new window
toOpen in new window
In the link to the other EE question I provided, it is pretty straight forward. Try and convert this on your own and let us know if you run into trouble.