#1
  1. A Change of Season
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2004
    Location
    Next Door
    Posts
    2,687
    Rep Power
    171

    How to respond to xml with xml?


    Hello

    I am exchanging data with a large data provider website via XML. They send me XML and they expect XML back. Now I have written a script that generates the response xml, but I don't know how to actually "send it back to them".
    This is what they send me:
    Code:
    <env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
      <env:Header>
        <wsse:Security soap:mustUnderstand='1' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/' xmlns:wsse='http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd'>
          <wsse:UsernameToken>
            <wsse:Username>Username</wsse:Username>
            <wsse:Password Type='http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText'>Password</wsse:Password>
          </wsse:UsernameToken>
        </wsse:Security>
      </env:Header>
      <env:Body>
        <OTA_HotelAvailRQ Version='1.0' TimeStamp='2012-07-20T09:41:02+10:00' EchoToken='abc123' AvailRatesOnly='true' xmlns='http://www.opentravel.org/OTA/2003/05'>
          <AvailRequestSegments>
            <AvailRequestSegment AvailReqType='Room'>
              <HotelSearchCriteria>
                <Criterion>
                  <HotelRef HotelCode='1961'/>
                </Criterion>
              </HotelSearchCriteria>
            </AvailRequestSegment>
          </AvailRequestSegments>
        </OTA_HotelAvailRQ>
      </env:Body>
    </env:Envelope>
    This is how I generate the response XML
    PHP Code:
    <?php if($_SERVER['HTTP_HOST']=='localhost')
        {
            include 
    "../my_local_connections.php";
        }
    else
        {
            include 
    "/home/h2g/includes/myconnections.php";    
        }
    $xml simplexml_load_file("receive.xml"); 
    $xml->registerXPathNamespace('ot''http://www.opentravel.org/OTA/2003/05');
    $hotel_ref $xml->xpath("//ot:HotelRef");
    $attributes $hotel_ref[0]->attributes();
    $hotel_id $attributes['HotelCode']; 
    $sql "SELECT hotelrooms.room_id   AS RID,
           hotelrooms.roomname,
           hotelrooms.roomdescription,
           hotelrooms.hotel_id AS HID,
           packages.id          AS PID,
           packages.description AS PD,
           packages.name        AS PN,
           packages.room_id     AS room_id
    FROM   hotelrooms
           INNER JOIN hotels
                   ON hotels.hotel_id = hotelrooms.hotel_id
           INNER JOIN channel_managers
                   ON channel_managers.id = hotels.channel_manager_id
           LEFT OUTER JOIN packages
                        ON packages.room_id = hotelrooms.room_id
    WHERE  hotelrooms.status = 'active'
           AND packages.status = 'active'
           AND channel_managers.id = 29
           AND hotels.hotel_id=:hotel_id
    ORDER  BY hotelrooms.room_id"
    ;
    $args = array('hotel_id'=>$hotel_id); 
    $number_of_rows DB::Load()->Execute($sql,$args)->returnNumAffectedRows();

    if(
    $number_of_rows != 0)
        {
        
    $data DB::Load()->Execute($sql,$args)->returnArray();
        
    $file fopen("OTA_HotelAvailRS.xml""w");
        
    //header("Content-type: text/xml");
        
    $_xml .= "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\r\n";
        
    $_xml "<env:Envelope xmlns:env=\"http://schemas.xmlsoap.org/soap/envelope/\">\r\n";
          
    $_xml .= "<env:Body>\r\n";
        
    $_xml .= "<OTA_HotelAvailRS xmlns=\"http://www.opentravel.org/OTA/2003/05\" Version=\"1.0\" TimeStamp=\"".date('c')."\" EchoToken=\"abc123\">\r\n";
        
    $_xml.="<Success/>\r\n";
        
    $_xml .= "\t<RoomStays>\r\n";
        foreach (
    $data as $tech =>$row)
            {
                if (
    $row["roomname"])
                    {
                        
                            
    $_xml .= "\t\t<RoomStay>\r\n";
                                
    $_xml .= "\t\t\t<RoomTypes>\r\n";
                                    
    $_xml .= "\t\t\t\t<RoomType RoomTypeCode=\"".htmlspecialchars($row["RID"], ENT_QUOTES"utf-8")."\">\r\n";
                                    
    $_xml .= "\t\t\t\t<HoteCode id=\"".htmlspecialchars($row["HID"], ENT_QUOTES"utf-8")."\">\r\n";
                                    
    $_xml .= "\t\t\t\t</HoteCode>\r\n";
                                    
                                        
    $_xml .= "\t\t\t\t\t<RoomDescription Name=\"".htmlspecialchars($row["roomname"], ENT_QUOTES"utf-8")."\">\r\n";
                                            
    $_xml .= "\t\t\t\t\t\t<Text>".htmlspecialchars($row["roomdescription"], ENT_QUOTES"utf-8")."</Text>\r\n";
                                        
    $_xml .= "\t\t\t\t\t</RoomDescription>\r\n";
                                    
    $_xml .= "\t\t\t\t</RoomType>\r\n";
                                
    $_xml .= "\t\t\t</RoomTypes>\r\n";
                    
                        
    //Rate Plans
                                
    if($row["PID"])
                                    {
                                        
    $_xml .= "\t\t\t<RatePlans>\r\n";
                                            
    $_xml .= "\t\t\t<RatePlan RatePlanCode=\"".htmlspecialchars($row["PID"], ENT_QUOTES"utf-8")."\">\r\n";
                                              
    $_xml .= "\t\t\t<RatePlanDescription Name=\"".htmlspecialchars($row["PN"], ENT_QUOTES"utf-8")."\"/>\r\n";
                                              
    $_xml .= "\t\t\t\t<Text>".htmlspecialchars($row["PD"], ENT_QUOTES"utf-8")."</Text>\r\n";
                                            
    $_xml .= "\t\t\t</RatePlan>\r\n";
                                        
    $_xml .= "\t\t\t</RatePlans>\r\n";
                                    }
                            
    $_xml .= "\t\t</RoomStay>\r\n";
                    }
              }
        
    $_xml .= "\t</RoomStays>\r\n";
        
    $_xml .= "</OTA_HotelAvailRS>";
        
    $_xml .= "</env:Body>";    
        
    $_xml .= "</env:Envelope>";    
        
    file_put_contents('OTA_HotelAvailRS.xml'$_xml);
        
    //echo "XML has been written.  <a href=\"OTA_HotelAvailRS.xml\">View the XML.</a>";
    }
    else
        {
            echo 
    "No Records found";
        }
    ?>
    Some quesitons answered:
    1 - How / how often do you access our server (send us the xml request)? Is it via a cron job or each time there is an update you send the request?

    For Room Retrieval and availability/rates updates these will come through as the property makes updates in their system, so depending on how often they are updating is how often you'll be receiving requests. For Availability/ Rates updates we can also do a full flush of data to you but this is only on request by the property.

    2 - I am writing a script to generate the respond xml (In reply to your xml). How do we get notified that your request has arrived?

    For Room Retrieval you'll know it has successfully completed if no errors are reported, for Availability and Rates because we are sending the request to you we rely on you sending back OTA_HotelAvailNotifRS for availability and OTA_HotelRateAmountNotifRS for Rates with a success tag in it, you can see this at https://siteminder.onconfluence.com/display/SITECONNECT/Inventory+Push+API. For reservations we'll be passing back OTA_HotelResNotifRS with a success or error response.
    They just sent me this:
    Did you have room information for HotelCode='1961'? The only response I'm getting from your xml is the following:

    XML has been written. <a href="OTA_HotelAvailRS.xml">View the XML.</a>

    I also noticed in the raw response the content type is text/html, this should be text/xml.
    How can I respond their xml with an xml?
    Last edited by zxcvbnm; July 26th, 2012 at 08:34 PM.
  2. #2
  3. Code Monkey V. 0.9
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Mar 2005
    Location
    A Land Down Under
    Posts
    2,129
    Rep Power
    1990
    PHP Code:
    header ("Content-type: text/xml");

    // Echo local file
    echo file_get_contents ("myxmlfile.xml");

    // OR

    // Echo variable with XML string
    echo $xml_string;

    die (); 
    That's pretty much all there is to it. Once you've got your XML worked out, you'd output that in the same way that you'd output any HTML file.
  4. #3
  5. No Profile Picture
    I haz teh codez!
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Dec 2003
    Posts
    2,552
    Rep Power
    2337
    I don't understand why you're futzing with building SOAP messages from raw XML when you should probably be using the SoapClient?

    Comments on this post

    • Jacques1 agrees : Definitely! At least he didn't use regex to process the XML. ;-)
    I ♥ ManiacDan & requinix

    This is a sig, and not necessarily a comment on the OP:
    Please don't be a help vampire!
  6. #4
  7. A Change of Season
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2004
    Location
    Next Door
    Posts
    2,687
    Rep Power
    171
    Originally Posted by ptr2void
    I don't understand why you're futzing with building SOAP messages from raw XML when you should probably be using the SoapClient?
    Can you show me some sample code?
  8. #5
  9. No Profile Picture
    I haz teh codez!
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Dec 2003
    Posts
    2,552
    Rep Power
    2337
    How about RTFM?
    I ♥ ManiacDan & requinix

    This is a sig, and not necessarily a comment on the OP:
    Please don't be a help vampire!
  10. #6
  11. A Change of Season
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2004
    Location
    Next Door
    Posts
    2,687
    Rep Power
    171
    Originally Posted by ptr2void
    How about RTFM?
    Be polite this is public.
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    3
    Rep Power
    0

    Unhappy How to response to WSDL with xml? :confused:


    I don't use the Soapclient and Soapserver functions, because I don't understand as all. I need to do only the server side to return the response.

    When testing have some problem with the xml. Requestor have been trying to work out, but he can't. he can see the response when he hit my service with SOAPUI but once he added the service details to the test service it broke and he can see a response coming.


    If I used a WSDL document, see some path of WSDL below:


    <wsdl:message name="OTA_HotelAvailRQMessage">
    <wsdlart element="wsse:Security" name="Security"/>
    <wsdlart element="ota:OTA_HotelAvailRQ" name="OTA_HotelAvailRQ"/>
    </wsdl:message>
    <wsdl:message name="OTA_HotelAvailRSMessage">
    <wsdlart element="ota:OTA_HotelAvailRS" name="OTA_HotelAvailRS"/>
    </wsdl:message>

    <wsdlperation name="HotelAvailRQ">
    <wsdl:input message="tns:OTA_HotelAvailRQMessage"/>
    <wsdlutput message="tns:OTA_HotelAvailRSMessage"/>
    </wsdlperation>

    How to return the response with invoke a WSDL operation (HotelAvailRQ) of the webservice?



    I get the content and generate the response as the codes below.
    =======================================
    $request = (isset($HTTP_RAW_POST_DATA)) ? $HTTP_RAW_POST_DATA : file_get_contents("php://input"); //access raw posted data

    $xml = simplexml_load_string(str_replace("SOAP-ENV","soap",$request));
    $xml->registerXPathNamespace('ot', 'urladdress');
    $hotel_ref = $xml->xpath("//ot:HotelRef");
    $hotel_att = $hotel_ref[0]->attributes();
    $hotelcode = $hotel_att['HotelCode'];

    .... then query to database and make the xml string, see some the codes below .....

    $xml = header("Content-type: text/xml charset=UTF-8");
    $xml .= "<soap:Envelope xmlns:soap=\"urladdress\">\n";
    $xml .= "\t<soap:Header xmlns:soap=\"urladdress\">";
    $xml .= "\t</soap:Header>\n";

    $xml .= "\t<soap:Body>\n";
    $xml .= "\t\t<OTA_HotelAvailRS xmlns=\"urladdress\" Version=\"1.0\" TimeStamp=\"".date(DATE_ATOM, time())."\" EchoToken=\"".$token."\">\n";

    $xml .= "\t\t</OTA_HotelAvailRS>\n";
    $xml .= "\t</soap:Body>\n";
    $xml .= "</soap:Envelope>";
    echo $xml;
    =======================================



    or I should be use the soapserver function below.
    =================================
    ini_set("soap.wsdl_cache_enabled", "0");
    $server = new SoapServer("urladdress");
    $server->addFunction("HotelAvailRQ");
    $server->handle();

    function HotelAvailRQ() {
    .... return the response

    }
    =======================================

    That is possible or not? Could you please anybody help me

IMN logo majestic logo threadwatch logo seochat tools logo