Link to home
Start Free TrialLog in
Avatar of ugurtan
ugurtan

asked on

Use SOAP Response in ASP

Hi;
    We've been working with a tour operator. We would like to get their information via XML SOAP web services.
    I requested informationfrom them via SOAP web services. I can get all the information. However, all information is in XML format and I need transform this to the HTML. You can figure out in below code snippet that "strMethodResultXML" give us the XML response. I can see XML response when I add the 'Response.Write strMethodResultXML' script to code. So, I would like to use this information logically. I don't have fixed .xml file on my server. You can find example XML response on this link: http://www.dundar.ch/hbeds/HOTRS.xml. I would like to transform these bulk XML response to the table format such as http://www.dundar.ch/hbeds/xmltabloyap.htm. I guess I have to use MSXML.DOMDocument but I couldn't get result with this object.

What advice can you give me?

Thanks in advance.


<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
 
<body>
<%
 
Dim objXMLHTTP : SET  objXMLHTTP = Server.CreateObject("Msxml2.XMLHTTP.3.0")
Dim objOutputXMLDoc : Set objOutputXMLDoc = Server.CreateObject("MSXML.DOMDocument")
 
Dim strMethodPkg
Dim strMethodResultXML
 
 
strMethodPkg ="<?xml version=""1.0"" encoding=""utf-8""?>"
strMethodPkg = strMethodPkg &"<soapenv:Envelope soapenv:encodingStyle=""http://schemas.xmlsoap.org/soap/encoding/"" xmlns:soapenv=""http://schemas.xmlsoap.org/soap/envelope/"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"">"
strMethodPkg = strMethodPkg & "<soapenv:Header/>"
strMethodPkg = strMethodPkg & "<soapenv:Body>"
strMethodPkg = strMethodPkg & "<hb:getHotelValuedAvail xmlns:hb=""http://axis.frontend.hydra.hotelbeds.com"" xsi:type=""xsd:string"">"
strMethodPkg = strMethodPkg & "<HotelValuedAvailRQ echoToken=""DummyEchoToken"" sessionId=""DummySessionId"" xmlns=""http://www.hotelbeds.com/schemas/2005/06/messages"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xsi:schemaLocation=""http://www.hotelbeds.com/schemas/2005/06/messages HotelValuedAvailRQ.xsd"">"
strMethodPkg = strMethodPkg & "<Language>ENG</Language>"
strMethodPkg = strMethodPkg & "<Credentials>"
strMethodPkg = strMethodPkg & "<User>XXX</User>"
strMethodPkg = strMethodPkg & "<Password>XXX</Password>"
strMethodPkg = strMethodPkg & "</Credentials>"
strMethodPkg = strMethodPkg & "<PaginationData pageNumber=""1""/>"
strMethodPkg = strMethodPkg & "<CheckInDate date=""20081028""/>"
strMethodPkg = strMethodPkg & "<CheckOutDate date=""20081030""/>"
strMethodPkg = strMethodPkg & "<Destination code=""LON"" type=""SIMPLE""/>"
strMethodPkg = strMethodPkg & "<OccupancyList>"
strMethodPkg = strMethodPkg & "<HotelOccupancy>"
strMethodPkg = strMethodPkg & "<RoomCount>1</RoomCount>"
strMethodPkg = strMethodPkg & "<Occupancy>"
strMethodPkg = strMethodPkg & "<AdultCount>2</AdultCount>"
strMethodPkg = strMethodPkg & "<ChildCount>0</ChildCount>"
strMethodPkg = strMethodPkg & "</Occupancy>"
strMethodPkg = strMethodPkg & "</HotelOccupancy>"
strMethodPkg = strMethodPkg & "</OccupancyList>"
strMethodPkg = strMethodPkg & "</HotelValuedAvailRQ>"
strMethodPkg = strMethodPkg & "</hb:getHotelValuedAvail>"
strMethodPkg = strMethodPkg & "</soapenv:Body>"
strMethodPkg = strMethodPkg & "</soapenv:Envelope>"
 
 
 
objXMLHTTP.open "post", "http://212.170.239.71/appservices/ws/FrontendService", False
 
objXMLHTTP.setRequestHeader "Content-Type", "text/xml; charset=utf-8"
objXMLHTTP.setRequestHeader "Content-Length", Len(strMethodPkg)
 
 
objXMLHTTP.setRequestHeader "SOAPAction", "http://212.170.239.71/appservices/ws/FrontendService"
 
 
 
Call objXMLHTTP.send(strMethodPkg)
 
strMethodResultXML = objXMLHTTP.responsetext
 
 %>
 
<script type="text/javascript">
var xmlDoc=null;
if (window.ActiveXObject)
{// code for IE
xmlDoc=new ActiveXObject("MSXML.DOMDocument");
}
else if (document.implementation.createDocument)
{// code for Firefox, Mozilla, Opera, etc.
xmlDoc=document.implementation.createDocument("","",null);
}
else
{
alert('Your browser cannot handle this script');
}
if (xmlDoc!=null)
{
xmlDoc.async=false;
xmlDoc.load(objXMLHTTP.responseBody);
 
document.write("<table border='1'>");
 
var x=xmlDoc.getElementsByTagName("ServiceHotel");
for (var i=0;i<x.length;i++)
{ 
document.write("<tr>");
document.write("<td>");
document.write(x[i].getElementsByTagName("Code")[0].childNodes[0].nodeValue);
document.write("</td>");
 
document.write("<td>");
document.write(x[i].getElementsByTagName("Name")[1].childNodes[0].nodeValue);
document.write("</td>");
document.write("</tr>");
}
document.write("</table>");
}
</script>
 
</p>
</body>
</html>

Open in new window

Avatar of hielo
hielo
Flag of Wallis and Futuna image


<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<div>
<%
Dim objXMLHTTP : SET  objXMLHTTP = Server.CreateObject("Msxml2.XMLHTTP.3.0")
Dim objOutputXMLDoc : Set objOutputXMLDoc = Server.CreateObject("MSXML2.DOMDocument.3.0")
Dim strMethodPkg
Dim strMethodResultXML
strMethodPkg ="<?xml version=""1.0"" encoding=""utf-8""?>"
strMethodPkg = strMethodPkg &"<soapenv:Envelope soapenv:encodingStyle=""http://schemas.xmlsoap.org/soap/encoding/"" xmlns:soapenv=""http://schemas.xmlsoap.org/soap/envelope/"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"">"
strMethodPkg = strMethodPkg & "<soapenv:Header/>"
strMethodPkg = strMethodPkg & "<soapenv:Body>"
strMethodPkg = strMethodPkg & "<hb:getHotelValuedAvail xmlns:hb=""http://axis.frontend.hydra.hotelbeds.com"" xsi:type=""xsd:string"">"
strMethodPkg = strMethodPkg & "<HotelValuedAvailRQ echoToken=""DummyEchoToken"" sessionId=""DummySessionId"" xmlns=""http://www.hotelbeds.com/schemas/2005/06/messages"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xsi:schemaLocation=""http://www.hotelbeds.com/schemas/2005/06/messages HotelValuedAvailRQ.xsd"">"
strMethodPkg = strMethodPkg & "<Language>ENG</Language>"
strMethodPkg = strMethodPkg & "<Credentials>"
strMethodPkg = strMethodPkg & "<User>XXX</User>"
strMethodPkg = strMethodPkg & "<Password>XXX</Password>"
strMethodPkg = strMethodPkg & "</Credentials>"
strMethodPkg = strMethodPkg & "<PaginationData pageNumber=""1""/>"
strMethodPkg = strMethodPkg & "<CheckInDate date=""20081028""/>"
strMethodPkg = strMethodPkg & "<CheckOutDate date=""20081030""/>"
strMethodPkg = strMethodPkg & "<Destination code=""LON"" type=""SIMPLE""/>"
strMethodPkg = strMethodPkg & "<OccupancyList>"
strMethodPkg = strMethodPkg & "<HotelOccupancy>"
strMethodPkg = strMethodPkg & "<RoomCount>1</RoomCount>"
strMethodPkg = strMethodPkg & "<Occupancy>"
strMethodPkg = strMethodPkg & "<AdultCount>2</AdultCount>"
strMethodPkg = strMethodPkg & "<ChildCount>0</ChildCount>"
strMethodPkg = strMethodPkg & "</Occupancy>"
strMethodPkg = strMethodPkg & "</HotelOccupancy>"
strMethodPkg = strMethodPkg & "</OccupancyList>"
strMethodPkg = strMethodPkg & "</HotelValuedAvailRQ>"
strMethodPkg = strMethodPkg & "</hb:getHotelValuedAvail>"
strMethodPkg = strMethodPkg & "</soapenv:Body>"
strMethodPkg = strMethodPkg & "</soapenv:Envelope>"
objXMLHTTP.open "post", "http://212.170.239.71/appservices/ws/FrontendService", False
objXMLHTTP.setRequestHeader "Content-Type", "text/xml; charset=utf-8"
objXMLHTTP.setRequestHeader "Content-Length", Len(strMethodPkg)
objXMLHTTP.setRequestHeader "SOAPAction", "http://212.170.239.71/appservices/ws/FrontendService"
Call objXMLHTTP.send(strMethodPkg)
strMethodResultXML = objXMLHTTP.responsetext
objOutputXMLDoc.loadXML strMethodResultXML
 
Set ServiceHotels = objOutputXMLDoc.selectNodes("/HotelValuedAvailRS/ServiceHotel")
For Each serviceHotel in ServiceHotels
	document.write "<div>" & serviceHotel.selectSingleNode("HotelInfo/Code").text & "</div>"  
	document.write "<div>" & serviceHotel.selectSingleNode("HotelInfo/Name").text & "</div>"  
Next
Set serviceHotel=Nothing
Set ServiceHotels=Nothing
objOutputXMLDoc=Nothing
%>
</div>
</body>
</html>

Open in new window

BTW:
document.write

shoud have been:
Response.Write

AND
objOutputXMLDoc=Nothing

should have been:
Set objOutputXMLDoc=Nothing
Avatar of ugurtan
ugurtan

ASKER

Hi hielo;

    First of all, thank you very much for your interest. I tried your suggestion but it couldn't get the results. You can see at http://www.dundar.ch/hbeds/deneme4.asp.

    Could you please check again the codes?

Looking forward to hearing from you

Thanks.
>>/hbeds/deneme4.asp, line 52
I don't see anything with  HTMLDecode on what I posted. Do you modified version of the script? Or is that the result that the remote page is sending back?

You need to make sure the remote page is sending back a valid XML result.
I tried the attached code and the response I get from the remote system is:
"You are not allowed to access the system"

This leads me to believe the error you are seeing is somewhere else in your code. Save what I provided below as test.asp and try it.
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!-- http://www.experts-exchange.com/Programming/Languages/Visual_Basic/Q_23847001.html -->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<div>
<%
Dim objXMLHTTP : SET  objXMLHTTP = Server.CreateObject("Msxml2.XMLHTTP.3.0")
Dim objOutputXMLDoc : Set objOutputXMLDoc = Server.CreateObject("MSXML2.DOMDocument.3.0")
Dim strMethodPkg
Dim strMethodResultXML
strMethodPkg ="<?xml version=""1.0"" encoding=""utf-8""?>"
strMethodPkg = strMethodPkg &"<soapenv:Envelope soapenv:encodingStyle=""http://schemas.xmlsoap.org/soap/encoding/"" xmlns:soapenv=""http://schemas.xmlsoap.org/soap/envelope/"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"">"
strMethodPkg = strMethodPkg & "<soapenv:Header/>"
strMethodPkg = strMethodPkg & "<soapenv:Body>"
strMethodPkg = strMethodPkg & "<hb:getHotelValuedAvail xmlns:hb=""http://axis.frontend.hydra.hotelbeds.com"" xsi:type=""xsd:string"">"
strMethodPkg = strMethodPkg & "<HotelValuedAvailRQ echoToken=""DummyEchoToken"" sessionId=""DummySessionId"" xmlns=""http://www.hotelbeds.com/schemas/2005/06/messages"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xsi:schemaLocation=""http://www.hotelbeds.com/schemas/2005/06/messages HotelValuedAvailRQ.xsd"">"
strMethodPkg = strMethodPkg & "<Language>ENG</Language>"
strMethodPkg = strMethodPkg & "<Credentials>"
strMethodPkg = strMethodPkg & "<User>XXX</User>"
strMethodPkg = strMethodPkg & "<Password>XXX</Password>"
strMethodPkg = strMethodPkg & "</Credentials>"
strMethodPkg = strMethodPkg & "<PaginationData pageNumber=""1""/>"
strMethodPkg = strMethodPkg & "<CheckInDate date=""20081028""/>"
strMethodPkg = strMethodPkg & "<CheckOutDate date=""20081030""/>"
strMethodPkg = strMethodPkg & "<Destination code=""LON"" type=""SIMPLE""/>"
strMethodPkg = strMethodPkg & "<OccupancyList>"
strMethodPkg = strMethodPkg & "<HotelOccupancy>"
strMethodPkg = strMethodPkg & "<RoomCount>1</RoomCount>"
strMethodPkg = strMethodPkg & "<Occupancy>"
strMethodPkg = strMethodPkg & "<AdultCount>2</AdultCount>"
strMethodPkg = strMethodPkg & "<ChildCount>0</ChildCount>"
strMethodPkg = strMethodPkg & "</Occupancy>"
strMethodPkg = strMethodPkg & "</HotelOccupancy>"
strMethodPkg = strMethodPkg & "</OccupancyList>"
strMethodPkg = strMethodPkg & "</HotelValuedAvailRQ>"
strMethodPkg = strMethodPkg & "</hb:getHotelValuedAvail>"
strMethodPkg = strMethodPkg & "</soapenv:Body>"
strMethodPkg = strMethodPkg & "</soapenv:Envelope>"
 
objXMLHTTP.open "POST", "http://212.170.239.71/appservices/ws/FrontendService", False
objXMLHTTP.setRequestHeader "Content-Type", "text/xml; charset=utf-8"
objXMLHTTP.setRequestHeader "Content-Length", Len(strMethodPkg)
objXMLHTTP.setRequestHeader "SOAPAction", "http://212.170.239.71/appservices/ws/FrontendService"
Call objXMLHTTP.send(strMethodPkg)
strMethodResultXML = objXMLHTTP.responsetext
Response.Write(strMethodResultXML)
objOutputXMLDoc.loadXML strMethodResultXML
 
Set ServiceHotels = objOutputXMLDoc.selectNodes("/HotelValuedAvailRS/ServiceHotel")
For Each serviceHotel in ServiceHotels
	Response.write "<div>" & serviceHotel.selectSingleNode("HotelInfo/Code").text & "</div>"  
	Response.write "<div>" & serviceHotel.selectSingleNode("HotelInfo/Name").text & "</div>"  
Next
Set serviceHotel=Nothing
Set ServiceHotels=Nothing
Set objOutputXMLDoc=Nothing
%>
</div>
</body>
</html>

Open in new window

Avatar of ugurtan

ASKER

Due to the security rules, remote system response to only registered IP's. We've static IP and registered their systems.
I tried your last script at:
http://www.swisshit.ch/hbeds/deneme7.asp
and you can see this address.

However, I couldn't get list view. Between row 54 and 58 doesn't work. What advice can you give me?

Thanks
>>Between row 54 and 58 doesn't work
If you look at :
Set ServiceHotels = objOutputXMLDoc.selectNodes("/HotelValuedAvailRS/ServiceHotel")
For Each serviceHotel in ServiceHotels
      Response.write "<div>" & serviceHotel.selectSingleNode("HotelInfo/Code").text & "</div>"  
      Response.write "<div>" & serviceHotel.selectSingleNode("HotelInfo/Name").text & "</div>"  
Next

it is basically trying to write the value of:
/HotelValuedAvailRS/ServiceHotel/HotelInfo/Code
and:
/HotelValuedAvailRS/ServiceHotel/HotelInfo/Name

In other words, your xml needs to have these:
<HotelValuedAvailRS>
 <ServiceHotel>
  <HotelInfo>
    <Code></Code>
    <Name></Name>
  </HotelInfo>
 </ServiceHotel>
</HotelValuedAvailRS>
 
If you look closer at the xml you are getting bak, those nodes do not exist. This is what that service is returning:
 
<HotelValuedAvailRS xmlns="http://www.hotelbeds.com/schemas/2005/06/messages" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.hotelbeds.com/schemas/2005/06/messages HotelValuedAvailRS.xsd" timeToExpiration="0" totalItems="0" echoToken="DummyEchoToken">
	<AuditData>
		<ProcessTime>27</ProcessTime>
		<Timestamp>2008-11-17 09:00:00.521</Timestamp>
		<RequestHost>82.195.225.124</RequestHost>
		<ServerName>TEST</ServerName>
		<ServerId>TS</ServerId>
		<SchemaRelease>2005/06</SchemaRelease>
		<HydraCoreRelease>2.0.200810101124</HydraCoreRelease>
		<HydraEnumerationsRelease>1.0.200810101124</HydraEnumerationsRelease>
		<MerlinRelease>N/A</MerlinRelease>
	</AuditData>
	<PaginationData currentPage="1" totalPages="1"/>
</HotelValuedAvailRS>
 
Given the xml that the service is returning, if you were interested in retrieving the values for:
 
		<ServerName>TEST</ServerName>
		<ServerId>TS</ServerId>
 
Then the necessary changes would be:
 
Set ServiceHotels = objOutputXMLDoc.selectNodes("/HotelValuedAvailRS/AuditData")
For Each serviceHotel in ServiceHotels
	Response.write "<div>" & serviceHotel.selectSingleNode("Servername").text & "</div>"  
	Response.write "<div>" & serviceHotel.selectSingleNode("ServerId").text & "</div>"  
Next
 
The bottom line is, lines 54...58 is not working because it is looking for non-exist nodes. In case you are wondering how I came up with:
Set ServiceHotels = objOutputXMLDoc.selectNodes("/HotelValuedAvailRS/ServiceHotel")
For Each serviceHotel in ServiceHotels
	Response.write "<div>" & serviceHotel.selectSingleNode("HotelInfo/Code").text & "</div>"  
	Response.write "<div>" & serviceHotel.selectSingleNode("HotelInfo/Name").text & "</div>"  
Next
 
in my original post, the answer is that I looked at what you posted, and that is what I gathered from the javascript portion of your problem description. Seeing the url you posted, it is evident that it would not work due to the non-exist nodes. Hopefully it is now clear how you would need to modify the script so you can obtain the values you actually need.

Open in new window

Avatar of ugurtan

ASKER

The system doesn't work sometime. Sometime I get same result. However, I suggest you should try again this link:

http://www.swisshit.ch/hbeds/deneme7.asp

It involves those nodes:
<HotelValuedAvailRS>
 <ServiceHotel>
  <HotelInfo>
    <Code></Code>
    <Name></Name>
  </HotelInfo>
 </ServiceHotel>
</HotelValuedAvailRS>

Looking forward to hearing from you

Best Regards,

Ugurtan
 
If you open the url you provided via a browser and look at the browser's source coe you will notice that all that "XML" is encoded/escaped. Instead of generating something like:
<tagName>...</tagName>
 
it is generating:
&lt;tagName&gt;...&lt;/tagName&gt;
 
That is NOT xml markup. That is just encoded "plainText" that looks like xml. So you need to take that response and convert change the &lt; to < and the &gt; to >
 
So, on post ID: 22876480, change line 50:
strMethodResultXML = objXMLHTTP.responsetext
 
 
TO:
strMethodResultXML = replace(replace(objXMLHTTP.responsetext,"&lt;","<"),"&gt;",">")

Open in new window

What's the status of this. Did you try my previous post? BTW: If you are able to make any changes on the remote site, you need to make sure the returned data is sent as XML. Currently the output is basically "encoded" plain text that looks like xml. The purspose of the replace function calls on my previous post is to decode the  less and greater than symbols so that the DOMDocument object sees the result as xml markup.
Avatar of ugurtan

ASKER

Actually, it works. However it solved the plain text - xml problem. I found some codes which you can find below. Ultimately, I get result what I want. So, maybe you suggest about the below code. It is working but maybe you have a comment about this.

Thanks for all.
set hotel = objOutputXMLDoc.documentelement.getelementsbytagname("ServiceHotel")
y=1
for each x in hotel 
response.write "Hotel Code:" & x.selectSingleNode("HotelInfo/Code").text & "<br>"
response.write "Hotel Name:" & x.selectSingleNode("HotelInfo/Name").text & "<br>"
set images = x.getelementsbytagname("Image")
	for each image in images
		response.write "Hotel Image:<img src=""" & image.selectSingleNode("Url").text & """><br>"
	next
y=y+1
next

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of hielo
hielo
Flag of Wallis and Futuna image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial