Click to See Complete Forum and Search --> : XML , Array Parsing


ajd335
06-13-2008, 04:57 PM
Hi all,
I am working on shipping module.
I have and XML script , which is below

$this->_xml_request =<<<XML
<?xml version="1.0"?>
<AccessRequest xml:lang="en-US">
<AccessLicenseNumber>$this->_access_key</AccessLicenseNumber>
<UserId></UserId>
<Password></Password>
</AccessRequest>
<?xml version="1.0"?>
<RatingServiceSelectionRequest xml:lang="en-US">
<Request>
<TransactionReference>
<CustomerContext>Shipping</CustomerContext>
<XpciVersion>1.0001</XpciVersion>
</TransactionReference>
<RequestAction>$this->_request_option</RequestAction>
<RequestOption>$this->_request_option</RequestOption>
</Request>
<PickupType>
<Code>01</Code>
</PickupType>
<Shipment>
<Shipper>
<ShipperNumber></ShipperNumber>
<Address>
<City></City>
<StateProvinceCode></StateProvinceCode>
<PostalCode></PostalCode>
<CountryCode></CountryCode>
</Address>
</Shipper>
<ShipTo>
<Address>
<StateProvinceCode>$s2</StateProvinceCode>
<PostalCode>$p2</PostalCode>
<CountryCode>US</CountryCode>
<ResidentialAddress>$r1</ResidentialAddress>
</Address>
</ShipTo>
<ShipFrom>
<Address>
<StateProvinceCode></StateProvinceCode >
<PostalCode></PostalCode>
<CountryCode></CountryCode>
</Address>
</ShipFrom>
<Service>
<Code>03</Code>
</Service>
<Package>
<PackagingType>
<Code>02</Code>
</PackagingType>
<PackageWeight>
<UnitOfMeasurement>
<Code>LBS</Code>
</UnitOfMeasurement>
<Weight>{$w2}</Weight>
</PackageWeight>
</Package>
<RateInformation>
<NegotiatedRatesIndicator/>
</RateInformation>
</Shipment>
</RatingServiceSelectionRequest>
XML;


which fetch the data and calculate the shipping charge from UPS.
the output response is below..


Array
(
[RatingServiceSelectionResponse] => Array
(
[Response] => Array
(
[TransactionReference] => Array
(
[CustomerContext] => Shipping
[XpciVersion] => 1.0001
)

[ResponseStatusCode] => 1
[ResponseStatusDescription] => Success
)

[RatedShipment] => Array
(
[Service] => Array
(
[Code] => 03
)

[RatedShipmentWarning] => Your invoice may vary from the displayed reference rates
[BillingWeight] => Array
(
[UnitOfMeasurement] => Array
(
[Code] => LBS
)

[Weight] => 36.0
)

[TransportationCharges] => Array
(
[CurrencyCode] => USD
[MonetaryValue] => 31.14
)

[ServiceOptionsCharges] => Array
(
[CurrencyCode] => USD
[MonetaryValue] => 0.00
)

[TotalCharges] => Array
(
[CurrencyCode] => USD
[MonetaryValue] => 31.14
)

[GuaranteedDaysToDelivery] =>
[ScheduledDeliveryTime] =>
[RatedPackage] => Array
(
[TransportationCharges] => Array
(
[CurrencyCode] => USD
[MonetaryValue] => 31.14
)

[ServiceOptionsCharges] => Array
(
[CurrencyCode] => USD
[MonetaryValue] => 0.00
)

[TotalCharges] => Array
(
[CurrencyCode] => USD
[MonetaryValue] => 31.14
)

[Weight] => 36.0
[BillingWeight] => Array
(
[UnitOfMeasurement] => Array
(
[Code] => LBS
)

[Weight] => 36.0
)

)

)

)

)
XML Resposne:
<?xml version="1.0"?><RatingServiceSelectionResponse><Response><TransactionReference><CustomerContext>Shipping</CustomerContext><XpciVersion>1.0001</XpciVersion></TransactionReference><ResponseStatusCode>1</ResponseStatusCode><ResponseStatusDescription>Success</ResponseStatusDescription></Response><RatedShipment><Service><Code>03</Code></Service><RatedShipmentWarning>Your invoice may vary from the displayed reference rates</RatedShipmentWarning><BillingWeight><UnitOfMeasurement><Code>LBS</Code></UnitOfMeasurement><Weight>36.0</Weight></BillingWeight><TransportationCharges><CurrencyCode>USD</CurrencyCode><MonetaryValue>31.14</MonetaryValue></TransportationCharges><ServiceOptionsCharges><CurrencyCode>USD</CurrencyCode><MonetaryValue>0.00</MonetaryValue></ServiceOptionsCharges><TotalCharges><CurrencyCode>USD</CurrencyCode><MonetaryValue>31.14</MonetaryValue></TotalCharges><GuaranteedDaysToDelivery></GuaranteedDaysToDelivery><ScheduledDeliveryTime></ScheduledDeliveryTime><RatedPackage><TransportationCharges><CurrencyCode>USD</CurrencyCode><MonetaryValue>31.14</MonetaryValue></TransportationCharges><ServiceOptionsCharges><CurrencyCode>USD</CurrencyCode><MonetaryValue>0.00</MonetaryValue></ServiceOptionsCharges><TotalCharges><CurrencyCode>USD</CurrencyCode><MonetaryValue>31.14</MonetaryValue></TotalCharges><Weight>36.0</Weight><BillingWeight><UnitOfMeasurement><Code>LBS</Code></UnitOfMeasurement><Weight>36.0</Weight></BillingWeight></RatedPackage></RatedShipment></RatingServiceSelectionResponse>


I wanted to store the value of MonetaryValue into $rate variable.
How can i do this..I thing I need to go for XML parsing...How to do so..I really
dont have any idea.
Thanks,