SOLVED Need help parsing answer

Good day,

Rookie learning PHP here.

I am trying to parse the answer back but I am stuck where it seem to me an array into an array? Sorry am I new to this.

Can anyone help with the below? I am unsure I have taken the right direction to begin with.

Thank You

my phph file : execute.php

<html>
    <head>
        <title>Get Rate Application</title>
        <link rel="stylesheet" href="https://code.jquery.com/ui/1.10.3/themes/mint-choc/jquery-ui.css" />
        <script src="https://code.jquery.com/jquery-1.9.1.js"></script>
        <script src="https://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
        <!--<link rel="stylesheet" href="/resources/demos/style.css" />-->
        <script>
            $(function() {
                $("#accordion").accordion();
            });
        </script>
    </head>

    <body>

<?php 
  

           
           $url = 'http://sellonline.canadapost.ca:30000';
           $xml = '<?xml version="1.0" ?>
<eparcel>

        <language>en</language>

        <ratesAndServicesRequest>

                <merchantCPCID> CPC_DEMO_XML </merchantCPCID>



                <fromPostalCode> k2k0b1 </fromPostalCode>

                <turnAroundTime> 24 </turnAroundTime>

                <itemsPrice>100.00</itemsPrice>


                <lineItems>
	                     <item>
                            <quantity> 1 </quantity>
                            <weight> 1.491 </weight>
                            <length> 1 </length>
                            <width> 1 </width>
                            <height> 1 </height>
                            <description> KAO Diskettes </description>
                        </item>
  
                        <item>
                            <quantity> 1 </quantity>
                            <weight> 1.5 </weight>
                            <length> 20 </length>
                            <width> 30 </width>
                            <height> 20 </height>
                            <description> My Ready To Ship Item</description>

                            <readyToShip/>
                        </item>
               </lineItems>

                <city> Toronto </city>

                <provOrState> ON </provOrState>


                <country>  CANADA </country>

                <postalCode> M4C1T2 </postalCode>
        </ratesAndServicesRequest>
</eparcel>';
           
           $ch = curl_init($url); // Create REST Request
           curl_setopt( $ch, CURLOPT_URL, $url );
           curl_setopt($ch, CURLOPT_POST, true);
		   curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
		   curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
		   curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: text/xml"));
		   curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);

            $curl_response = curl_exec($ch); // Execute REST Request
            if (curl_errno($ch)) {
                echo 'Curl error: ' . curl_error($ch) . '\n';
            }

echo 'HTTP Response Status: ' . curl_getinfo($ch,CURLINFO_HTTP_CODE) . '<br />';

            curl_close($ch);

				// Example of using SimpleXML to parse xml response
            libxml_use_internal_errors(true);
            $xml = simplexml_load_string($curl_response);
  
    if (!$xml) {
                echo "Failed loading XML\n";
                echo "$curl_response\n";
                foreach (libxml_get_errors() as $error) {
                    echo "\t" . $error->message;
                }
            } else {
			if ($xml->{'ratesAndServicesResponse'} ) {
				$ratesAndServicesResponse = $xml->{'ratesAndServicesResponse'};
			echo "<center><font color='black'><h3>Status Code " . $ratesAndServicesResponse->{"statusCode"} . "</font></h3></center>";
			echo "<center><font color='black'><h3>Status Message " . $ratesAndServicesResponse->{"statusMessage"} . "</font></h3></center>";
			echo "<center><font color='black'><h3>request ID " . $ratesAndServicesResponse->{"requestID"} . "</font></h3></center>";
			echo "<center><font color='black'><h3>handling " . $ratesAndServicesResponse->{"handling"} . "</font></h3></center>";
			echo "<center><font color='black'><h3>language " . $ratesAndServicesResponse->{"language"} . "</font></h3></center>";
 if ($ratesAndServicesResponse->{'product'} ) {
			 foreach ($ratesAndServicesResponse->{'product'} as $Products){
				 echo "<center><font color='black'><h3>Product ID " . $Products->{'ratesAndServicesResponse'}->{'product'} . "</font></h3></center>";
								// echo "<center><font color='black'><h3>Product ID " . $Products->{'ratesAndServicesResponse'}->{'product'}->{'name'} . "</font></h3></center>";
				
		    }
    }
		
			}
			}
			
		
		   
		 print_r($xml);


               
  ?>    
  
    </body>
</html> 
Sponsor our Newsletter | Privacy Policy | Terms of Service