Hey all
I am working on Shipping module....And i have one XML script which all gives me the below output :
XML Resposne: - <?xml version="1.0"?>
-
<CustomerContext> Shipping1.0001
-
<ResponseStatusCode>1
-
Success</ResponseStatusDescription>03
-
</Code>Your invoice may vary from the displayed reference rates
-
<Code>LBS
-
</UnitOfMeasurement>55.0
-
</BillingWeight>
-
<TransportationCharges>USD
-
<MonetaryValue>44.59
-
<ServiceOptionsCharges>
-
<CurrencyCode>USD0.00
-
</MonetaryValue>USD
-
</CurrencyCode>44.59
-
<GuaranteedDaysToDelivery>
-
</ScheduledDeliveryTime>
-
USD</CurrencyCode>
-
<MonetaryValue>44.59
-
<ServiceOptionsCharges>USD0.00
-
</MonetaryValue>USD
-
</CurrencyCode>44.59
-
55.0</Weight>LBS
-
</UnitOfMeasurement>55.0
-
</RatedShipment>
-
My question is <TotalCharges><CurrencyCode>USD</CurrencyCode><MonetaryValue>44.59
</MonetaryValue></TotalCharges>
In the above one , i want to store the value of that MonetaryValue which is 44.59 into one variable.....
how can i do that...
just to show , below is the XML which i have used -
$this->_xml_request =<<<XML
-
<?xml version="1.0"?>
-
<AccessRequest xml:lang="en-US">
-
<AccessLicenseNumber></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></Code>
-
</PickupType>
-
<Shipment>
-
<Shipper>
-
<ShipperNumber></ShipperNumber>
-
<Address>
-
<City></City>
-
<StateProvinceCode></StateProvinceCode>
-
<PostalCode></PostalCode>
-
<CountryCode></CountryCode>
-
</Address>
-
</Shipper>
-
<ShipTo>
-
<Address>
-
<StateProvinceCode>$state</StateProvinceCode>
-
<PostalCode>$postal_code</PostalCode>
-
<CountryCode>$country</CountryCode>
-
<ResidentialAddress>0</ResidentialAddress>
-
</Address>
-
</ShipTo>
-
<ShipFrom>
-
<Address>
-
<StateProvinceCode></StateProvinceCode >
-
<PostalCode></PostalCode>
-
<CountryCode></CountryCode>
-
</Address>
-
</ShipFrom>
-
<Service>
-
<Code></Code>
-
</Service>
-
<Package>
-
<PackagingType>
-
<Code></Code>
-
</PackagingType>
-
<PackageWeight>
-
<UnitOfMeasurement>
-
<Code>LBS</Code>
-
</UnitOfMeasurement>
-
<Weight>$weight</Weight>
-
</PackageWeight>
-
</Package>
-
<RateInformation>
-
<NegotiatedRatesIndicator/>
-
</RateInformation>
-
</Shipment>
-
</RatingServiceSelectionRequest>
-
XML;
-
can you help me , how i can store the value ?
12 1593
Hey all..
below is the response which i get when i run my script
XML Resposne: - <?xml version="1.0"?>
-
<CustomerContext> Shipping1.0001
-
</TransactionReference>
-
<ResponseStatusCode>1
-
<ResponseStatusDescription>Success
-
<RatedShipment>03
-
<RatedShipmentWarning>Your invoice may vary from the displayed reference rates
-
<UnitOfMeasurement>LBS
-
</UnitOfMeasurement>36.0
-
</BillingWeight>
-
<CurrencyCode>USD
-
<MonetaryValue>31.14
-
</TransportationCharges>
-
<ServiceOptionsCharges>
-
<CurrencyCode>USD
-
<MonetaryValue>0.00
-
</ServiceOptionsCharges>
-
<TotalCharges>USD
-
<MonetaryValue>31.14
-
<GuaranteedDaysToDelivery>
-
</GuaranteedDaysToDelivery>
-
</ScheduledDeliveryTime>
-
<RatedPackage>
-
<CurrencyCode>USD
-
<MonetaryValue>31.14
-
</TransportationCharges>
-
<CurrencyCode>USD
-
<MonetaryValue>0.00
-
</ServiceOptionsCharges>
-
<CurrencyCode>USD
-
<MonetaryValue>31.1436.0
-
<BillingWeight>
-
<Code>LBS36.0
-
</BillingWeight>
-
-
I want to convert that text into array..actually i wanted to store the value of Monetaryvalue which is 31.14 here into one variable..How cam i do this...
<TotalCharges><CurrencyCode>USD</CurrencyCode><MonetaryValue>31.14</MonetaryValue></TotalCharges>
You can read XML files in PHP using SimpleXML.
For something really simple as this, I would recommend a scripting language to find the regular expression bounded by the start and end tags.
It's a lot faster, although not as rigorous.
For something really simple as this, I would recommend a scripting language to find the regular expression bounded by the start and end tags.
It's a lot faster, although not as rigorous.
Hi jkmyoung ,
yeah may be that will be a good idea...
I have tried out
$var = preg_match("/<TotalCharges><CurrencyCode>USD<\/CurrencyCode><MonetaryValue>^(.*)$<\/MonetaryValue>/
",$str,$matches);
because i wanted the string which is 31.14 (that may change e'time) , but not working
Do you have any idea, why its not working ??
Hi jkmyoung ,
yeah may be that will be a good idea...
I have tried out
$var = preg_match("/<TotalCharges><CurrencyCode>USD<\/CurrencyCode><MonetaryValue>^(.*)$<\/MonetaryValue>/
",$str,$matches);
because i wanted the string which is 31.14 (that may change e'time) , but not working
Do you have any idea, why its not working ??
Your XML file seems to have many MonetaryValue tags, some of them with different values as well.
Your XML file seems to have many MonetaryValue tags, some of them with different values as well.
Hi,
I have tried out many XML functions , but it dint work correctly, so i was trying to use regular expression.
Yes , it does contain more than one monetary value , But i want the Monetary value which is under Total Charges array.. -
<?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 have tried below expression , but dint work... -
I tried out
-
$str = $_xml_response;
-
$var = preg_match("/<TotalCharges><CurrencyCode>
-
USD<\/CurrencyCode><MonetaryVa
-
lue>^(.*)$<\/MonetaryValue>/",$str,$matches);
-
if($var =true){
-
echo $matches[0];
-
You realize of course that
is not the same as
You realize of course that
is not the same as
hi,
yeah , It was by mistake , but still my pregmatch statment is showing no matches ...do you have any idea . how to solve so?
Thanks ,
hi,
yeah , It was by mistake , but still my pregmatch statment is showing no matches ...do you have any idea . how to solve so?
Thanks ,
What is the current output of your program?
What is the current output of your program?
hi,
My XML_response from UPS API is (the output ) -
<?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>
-
-
and using the preg_match as -
$str = $shipping->_xml_response;
-
-
$var = preg_match("/<TotalCharges><CurrencyCode>USD<\/CurrencyCode><MonetaryValu
-
e>(.*)<\/MonetaryValue>/",$str,$matches);
-
if($var == true){
-
echo $matches[0];}else echo "no match";
-
-
using above preg_match I am getting o/p as USD31.14USD31.14USD0.00USD31.14
and i just wanted to have 31.14 $......the last 31.14 (not the first one, not the 0.00 but the last 31.14 )...thanks
If you know that it's always the last one, then why not snip it off from the returned value.
If you know that it's always the last one, then why not snip it off from the returned value.
Hi ,
I have made some changes in perg_match statement and now its working fine..
Thanks.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: iffy agbim |
last post by:
I have a form that displays information selected from an Access Data
base. A select statement is used to do this on my asp page
SQLQuery = "SELECT * FROM tblopgaCOm2 WHERE billNo = '"
&...
|
by: serge calderara |
last post by:
Dear all,
I am retriving the atribute of an assembly by using :
obj = System.Reflection.Assembly.LoadFrom
(sFile).GetCustomAttributes(True)
Then fetching attribute object as folllow:
...
|
by: jeghers |
last post by:
i have a page where info can be inserted in a form that consists of some
textarea and some textfield.
but when i get to the page, i want the last inserted info, which is saved in
a database, to...
|
by: balakrishnan.dinesh |
last post by:
Hi frnds,
Im having a problem with retriving "\" backslash , In my
javascript client side page , ill get the response from the server side
, the response will contain some url like...
|
by: Kunal Nandi |
last post by:
can any one give me the code for uploading and retriving image using Blob, with jsp at front end and oracle8i at the back end ???????
i have tried this using long raw datatype i was able to upload...
|
by: soma.gunasekaran |
last post by:
Hi All ,
I've stored the Image file..... But i want to retriving the Image
files from MSACCSS 2003 (JPEG,bmp,Gif and etc....) So Pls help
me........ help me...............
Thanking you,...
|
by: kavithadevan |
last post by:
Hi,
I am trying to retriving some datas from the database.using submit button i am getting result but i inserted one submit image and i gave link to that image and then i run that script but its...
|
by: kaleeswaran |
last post by:
ResultSet rs=st.executeQuery("select i_sign from t_customer_photo where n_customer_id=1");
while(rs.next())
{
byte...
|
by: prabhakarbtechit |
last post by:
Hi,
i am beginer in .net i have stored Free Text Box values i mean html content, while retriving that values i have to substring it, so after substring that values it comes with html tags in...
|
by: pchaitanya |
last post by:
hi all,
suppose in a table if i have columns namely name,entrydate
now on retriving and binding to a gridview how can I get names rowwise and entrydate columnwise on a gridview
on...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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: 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: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
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: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |