Hey ,
I have a function called get_rate, the code for the get_rate is below. I call that function in which i have added the UPS XML script.And the answer I am getting is as below. -
XML Resposne:
-
THE Code for Get_rate() function is ,
-
function getRate(
-
$w2,
-
$s2,
-
$r1,
-
$p2,
-
$c2,
-
$service_code
-
) {
-
-
$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;
-
-
AND BELOW is the answer what I got ............
-
-
<?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>
-
My Question is, I want to store the value of MonetaryValue - the cost of the package field which is 31.14 into one variable , so that i can store it in database,
Do you plz tell me how to do so...I will really be thankful..
Thanks,
9 1634 dlite922 1,584
Recognized Expert Top Contributor
Have you heard of http://php.net/simple_xml?
check the last two depending on how your getting your xml, as a file or as a string.
then you can access the XML as you would an array, BUT although it acts like it, PHP still treats as an xml object. copy the values you need into your array and you should be set.
Have you heard of http://php.net/simple_xml?
check the last two depending on how your getting your xml, as a file or as a string.
then you can access the XML as you would an array, BUT although it acts like it, PHP still treats as an xml object. copy the values you need into your array and you should be set.
hey Dlite992,
Thanks, but i don't have XML file...Actually i have 1 php script page, in which i have included the below XML -
-
I have a function called get_rate, the code for the get_rate is below.
-
XML Resposne:
-
THE Code for Get_rate() function is ,
-
function getRate(
-
$w2,
-
$s2,
-
$r1,
-
$p2,
-
$c2,
-
$service_code
-
) {
-
-
$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;
-
AND BELOW is the answer what I got , that is generated by UPS API which i am calling in the program , and the resulting response is ,...... -
<?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 have the MonetaryValue filed to be stored into one variable.....(i.e 31.14 to be stored in a variable).
<TotalCharges><CurrencyCode>USD</CurrencyCode><MonetaryValue>31.14</MonetaryValue></TotalCharges>
[/code]
I have used xmlrpc_decode , but dint work..can you please suggest me what can be done?
Markus 6,050
Recognized Expert Expert
You have posted this three times.
Give people a chance to answer your questions!
You have posted this three times.
Give people a chance to answer your questions!
Hi Markus ,
yeah I posted the same but , the other times I need some XML to PHP parsing method...But i solved that , and now i needed to just have a string matching function , so i again posted that ....The purpose is different in all..
Use SimpleXML (PHP5): -
<?php
-
/* $xmlstr is the XML string */
-
$xml = simplexml_load_string($xmlstr);
-
-
$monetary_value = $xml->RatedShipment->TotalCharges->MonetaryValue;
-
-
print $monetary_value; /* will print: 31.14 */
-
?>
-
Atli 5,058
Recognized Expert Expert
I want to store the value of
<TotalCharges><CurrencyCode>USD</CurrencyCode><MonetaryValue>31.14</MonetaryValue></TotalCharges>
value of MonetaryValue field which is 31.14 in one variable..
How can i use preg_match or ereg here ???
I guess you could use regex, somewhat like this: -
// Replace 'tagname' with the tag you want to find
-
$regex = '/\<tagname\>([\d\.]+)\<\/tagname\>/is'
-
preg_match_all($regex, $string, $matches);
-
print_r($matches);
-
But the preferred method would probably be to use the XML functions, as nashruddin suggested.
pbmods 5,821
Recognized Expert Expert
Heya, AJD.
Play around with SimpleXML. You should be able to do something like this: -
$parser = new SimpleXMLElement($xmlData);
-
echo $parser->RatingServiceSelectionResponse->Response->RatedShipment->TransportationCharges->MonetaryValue;
-
Atli 5,058
Recognized Expert Expert
Hi Markus ,
yeah I posted the same but , the other times I need some XML to PHP parsing method...But i solved that , and now i needed to just have a string matching function , so i again posted that ....The purpose is different in all..
The three threads you posted were pretty much identical. They were all asking for a solution to the same problem, even if the means to which you wanted to reach this solution was slightly different for each one.
They were, in fact, so similar that they three different people provided pretty much the same solution to all of them.
So, to avoid confusion, I have merged them all into this one.
In the future, please try not to post the same problem multiple times, even if you are looking for different ways to fix it. It is much simpler to just ask again in the same thread. That way people will at least see what you have already been doing.
Thanks. Moderator
Hey all..
Thanks for the help....Now its working fine....
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Xah Lee |
last post by:
# -*- coding: utf-8 -*-
# Python
# Matching string patterns
#
# Sometimes you want to know if a string is of
# particular pattern. Let's say in your website
# you have converted all images...
|
by: Niko |
last post by:
Hi ,
I am writing script using multiple pattern matching.
I need to replace the $_ =~ few times.
Example:
sub xx {
open (TEMPF,"> $T_FILE");
|
by: Henry |
last post by:
I have a table that stores a list of zip codes using a varchar column type,
and I need to perform some string prefix pattern matching search. Let's say
that I have the columns:
94000-1235
94001...
|
by: Day Of The Eagle |
last post by:
Jeff_Relf wrote:
> ...yet you don't even know what RegEx is.
>
I'm looking at the source code for mono's Regex implementation right
now. You can download that source here ( use the class...
|
by: Tom Warren |
last post by:
I found a c program called similcmp on the net and converted it to vba
if anybody wants it. I'll post the technical research on it if there
is any call for it. It looks like it could be a useful...
| |
by: javuchi |
last post by:
I'm searching for a library which makes aproximative string matching,
for example, searching in a dictionary the word "motorcycle", but
returns similar strings like "motorcicle".
Is there such a...
|
by: olaufr |
last post by:
Hi,
I'd need to perform simple pattern matching within a string using a
list of possible patterns. For example, I want to know if the substring
starting at position n matches any of the string I...
|
by: Kevin CH |
last post by:
Hi,
I'm currently running into a confusion on regex and hopefully you guys
can clear it up for me.
Suppose I have a regular expression (0|(1(01*0)*1))* and two test
strings: 110_1011101_ and...
|
by: regis |
last post by:
Greetings,
about scanf matching nonempty sequences using the "%" matches a nonempty sequence of anything except '-'
"%" matches a nonempty sequence of anything except ']" matches a nonempty...
|
by: tech |
last post by:
Hi, I need a function to specify a match pattern including using
wildcard characters as below
to find chars in a std::string.
The match pattern can contain the wildcard characters "*" and "?",...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| |
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |