473,396 Members | 2,010 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

retriving value :

123 100+
Hey all
I am working on Shipping module....And i have one XML script which all gives me the below output :

XML Resposne:
Expand|Select|Wrap|Line Numbers
  1.  <?xml version="1.0"?>
  2. <CustomerContext> Shipping1.0001
  3. <ResponseStatusCode>1
  4. Success</ResponseStatusDescription>03
  5. </Code>Your invoice may vary from the displayed reference rates
  6. <Code>LBS
  7. </UnitOfMeasurement>55.0
  8. </BillingWeight>
  9. <TransportationCharges>USD
  10. <MonetaryValue>44.59
  11. <ServiceOptionsCharges>
  12. <CurrencyCode>USD0.00
  13. </MonetaryValue>USD
  14. </CurrencyCode>44.59
  15. <GuaranteedDaysToDelivery>
  16. </ScheduledDeliveryTime>
  17. USD</CurrencyCode>
  18. <MonetaryValue>44.59
  19. <ServiceOptionsCharges>USD0.00
  20. </MonetaryValue>USD
  21. </CurrencyCode>44.59
  22. 55.0</Weight>LBS
  23. </UnitOfMeasurement>55.0
  24. </RatedShipment>
  25.  
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

Expand|Select|Wrap|Line Numbers
  1. $this->_xml_request =<<<XML
  2. <?xml version="1.0"?>
  3. <AccessRequest xml:lang="en-US">
  4. <AccessLicenseNumber></AccessLicenseNumber>
  5. <UserId></UserId>
  6. <Password></Password>
  7. </AccessRequest>
  8. <?xml version="1.0"?>
  9. <RatingServiceSelectionRequest xml:lang="en-US">
  10.    <Request>
  11.       <TransactionReference>
  12.          <CustomerContext>Shipping</CustomerContext>
  13.          <XpciVersion>1.0001</XpciVersion>
  14.       </TransactionReference>
  15.       <RequestAction>$this->_request_option</RequestAction>
  16.       <RequestOption>$this->_request_option</RequestOption>
  17.    </Request>
  18.    <PickupType>
  19.       <Code></Code>
  20.    </PickupType>
  21.  <Shipment>
  22.       <Shipper>
  23.         <ShipperNumber></ShipperNumber>
  24.         <Address>
  25.         <City></City>
  26.         <StateProvinceCode></StateProvinceCode>
  27.          <PostalCode></PostalCode>
  28.          <CountryCode></CountryCode>
  29.          </Address>
  30.       </Shipper>
  31.       <ShipTo>
  32.          <Address>
  33.         <StateProvinceCode>$state</StateProvinceCode>
  34.             <PostalCode>$postal_code</PostalCode>
  35.             <CountryCode>$country</CountryCode>
  36. <ResidentialAddress>0</ResidentialAddress>
  37.          </Address>
  38.       </ShipTo>
  39.       <ShipFrom>
  40.          <Address>
  41.         <StateProvinceCode></StateProvinceCode >
  42.                 <PostalCode></PostalCode>
  43.                 <CountryCode></CountryCode>
  44.          </Address>
  45.       </ShipFrom>
  46.       <Service>
  47.          <Code></Code>
  48.       </Service>
  49.       <Package>
  50.          <PackagingType>
  51.             <Code></Code>
  52.          </PackagingType>
  53.          <PackageWeight>
  54.             <UnitOfMeasurement>
  55.                <Code>LBS</Code>
  56.             </UnitOfMeasurement>
  57.             <Weight>$weight</Weight>
  58.          </PackageWeight>
  59.       </Package>
  60.       <RateInformation>
  61.   <NegotiatedRatesIndicator/>
  62.       </RateInformation>
  63.    </Shipment>
  64. </RatingServiceSelectionRequest>
  65. XML;
  66.  
can you help me , how i can store the value ?
Jun 13 '08 #1
12 1593
ajd335
123 100+
Hey all..
below is the response which i get when i run my script


XML Resposne:
Expand|Select|Wrap|Line Numbers
  1.  <?xml version="1.0"?>
  2. <CustomerContext> Shipping1.0001
  3. </TransactionReference>
  4. <ResponseStatusCode>1
  5. <ResponseStatusDescription>Success
  6. <RatedShipment>03
  7. <RatedShipmentWarning>Your invoice may vary from the displayed reference rates
  8. <UnitOfMeasurement>LBS
  9. </UnitOfMeasurement>36.0
  10. </BillingWeight>
  11. <CurrencyCode>USD
  12. <MonetaryValue>31.14
  13. </TransportationCharges>
  14. <ServiceOptionsCharges>
  15. <CurrencyCode>USD
  16. <MonetaryValue>0.00
  17. </ServiceOptionsCharges>
  18. <TotalCharges>USD
  19. <MonetaryValue>31.14
  20. <GuaranteedDaysToDelivery>
  21. </GuaranteedDaysToDelivery>
  22. </ScheduledDeliveryTime>
  23. <RatedPackage>
  24. <CurrencyCode>USD
  25. <MonetaryValue>31.14
  26. </TransportationCharges>
  27. <CurrencyCode>USD
  28. <MonetaryValue>0.00
  29. </ServiceOptionsCharges>
  30. <CurrencyCode>USD
  31. <MonetaryValue>31.1436.0
  32. <BillingWeight>
  33. <Code>LBS36.0
  34. </BillingWeight>
  35.  
  36.  
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>
Jun 16 '08 #2
r035198x
13,262 8TB
You can read XML files in PHP using SimpleXML.
Jun 17 '08 #3
jkmyoung
2,057 Expert 2GB
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.
Jun 17 '08 #4
ajd335
123 100+
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 ??
Jun 17 '08 #5
r035198x
13,262 8TB
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.
Jun 18 '08 #6
ajd335
123 100+
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..
Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0"?><RatingServiceSelectionResponse><Response>
  2. <TransactionReference>
  3. <CustomerContext> Shipping</CustomerContext><XpciVersion>1.0001
  4. </XpciVersion></TransactionReference>
  5. <ResponseStatusCode>1</ResponseStatusCode>
  6. <ResponseStatusDescription>Success
  7. </ResponseStatusDescription></Response>
  8. <RatedShipment><Service><Code>03</Code></Service>
  9. <RatedShipmentWarning>Your invoice may vary from the displayed reference rates</RatedShipmentWarning><BillingWeight><UnitOfMeasurement>
  10. <Code>LBS</Code></UnitOfMeasurement><Weight>36.0</Weight>
  11. </BillingWeight><TransportationCharges>
  12. <CurrencyCode>USD</CurrencyCode>
  13. <MonetaryValue>31.14</MonetaryValue></TransportationCharges>
  14. <ServiceOptionsCharges><CurrencyCode>USD</CurrencyCode>
  15. <MonetaryValue>0.00</MonetaryValue></ServiceOptionsCharges>
  16. <TotalCharges><CurrencyCode>USD</CurrencyCode>
  17. <MonetaryValue>31.14</MonetaryValue></TotalCharges>
  18. <GuaranteedDaysToDelivery>
  19. </GuaranteedDaysToDelivery><ScheduledDeliveryTime>
  20. </ScheduledDeliveryTime>
  21. <RatedPackage><TransportationCharges>
  22. <CurrencyCode>USD</CurrencyCode>
  23. <MonetaryValue>31.14</MonetaryValue></TransportationCharges>
  24. <ServiceOptionsCharges><CurrencyCode>USD
  25. </CurrencyCode><MonetaryValue>0.00</MonetaryValue>
  26. </ServiceOptionsCharges><TotalCharges>
  27. <CurrencyCode>USD</CurrencyCode>
  28. <MonetaryValue>31.14</MonetaryValue></TotalCharges>
  29. <Weight>36.0</Weight>
  30. <BillingWeight><UnitOfMeasurement><Code>LBS</Code>
  31. </UnitOfMeasurement><Weight>36.0</Weight></BillingWeight>
  32. </RatedPackage></RatedShipment></RatingServiceSelectionResponse>
  33.  
  34.  
I have tried below expression , but dint work...

Expand|Select|Wrap|Line Numbers
  1. I tried out
  2. $str = $_xml_response;
  3. $var = preg_match("/<TotalCharges><CurrencyCode>
  4. USD<\/CurrencyCode><MonetaryVa
  5. lue>^(.*)$<\/MonetaryValue>/",$str,$matches);
  6. if($var =true){
  7. echo $matches[0];
  8.  
Jun 18 '08 #7
r035198x
13,262 8TB
You realize of course that
Expand|Select|Wrap|Line Numbers
  1. if($val = true)
is not the same as
Expand|Select|Wrap|Line Numbers
  1. if($val == true)
Jun 18 '08 #8
ajd335
123 100+
You realize of course that
Expand|Select|Wrap|Line Numbers
  1. if($val = true)
is not the same as
Expand|Select|Wrap|Line Numbers
  1. if($val == true)
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 ,
Jun 18 '08 #9
r035198x
13,262 8TB
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?
Jun 18 '08 #10
ajd335
123 100+
What is the current output of your program?
hi,
My XML_response from UPS API is (the output )
Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0"?><RatingServiceSelectionResponse><Response><TransactionReference><CustomerContext> Shipping</CustomerContext>
  2. <XpciVersion>1.0001</XpciVersion></TransactionReference>
  3. <ResponseStatusCode>1</ResponseStatusCode>
  4. <ResponseStatusDescription>Success</ResponseStatusDescription>
  5. </Response><RatedShipment><Service><Code>03</Code></Service><RatedShipmentWarning>Your invoice may vary from the displayed reference rates</RatedShipmentWarning><BillingWeight><UnitOfMeasurement>
  6. <Code>LBS</Code></UnitOfMeasurement><Weight>36.0</Weight></BillingWeight>
  7. <TransportationCharges><CurrencyCode>USD</CurrencyCode>
  8. <MonetaryValue>31.14</MonetaryValue></TransportationCharges>
  9. <ServiceOptionsCharges><CurrencyCode>USD</CurrencyCode>
  10. <MonetaryValue>0.00</MonetaryValue></ServiceOptionsCharges>
  11. <TotalCharges><CurrencyCode>
  12. USD</CurrencyCode><MonetaryValue>31.14</MonetaryValue>
  13. </TotalCharges><GuaranteedDaysToDelivery></GuaranteedDaysToDelivery>
  14. <ScheduledDeliveryTime></ScheduledDeliveryTime>
  15. <RatedPackage><TransportationCharges>
  16. <CurrencyCode>USD</CurrencyCode>
  17. <MonetaryValue>31.14</MonetaryValue>
  18. </TransportationCharges><ServiceOptionsCharges>
  19. <CurrencyCode>USD</CurrencyCode>
  20. <MonetaryValue>0.00</MonetaryValue></ServiceOptionsCharges>
  21. <TotalCharges><CurrencyCode>USD</CurrencyCode>
  22. <MonetaryValue>31.14</MonetaryValue></TotalCharges>
  23. <Weight>36.0</Weight><BillingWeight>
  24. <UnitOfMeasurement>
  25. <Code>LBS</Code>
  26. </UnitOfMeasurement><Weight>36.0</Weight>
  27. </BillingWeight></RatedPackage></RatedShipment></RatingServiceSelectionResponse>
  28.  
  29.  
and using the preg_match as


Expand|Select|Wrap|Line Numbers
  1. $str = $shipping->_xml_response;
  2.  
  3. $var = preg_match("/<TotalCharges><CurrencyCode>USD<\/CurrencyCode><MonetaryValu
  4. e>(.*)<\/MonetaryValue>/",$str,$matches);
  5. if($var == true){
  6. echo $matches[0];}else echo "no match";
  7.  
  8.  
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
Jun 18 '08 #11
r035198x
13,262 8TB
If you know that it's always the last one, then why not snip it off from the returned value.
Jun 19 '08 #12
ajd335
123 100+
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.
Jun 19 '08 #13

Sign in to post your reply or Sign up for a free account.

Similar topics

11
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 = '" &...
1
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: ...
2
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...
2
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...
1
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...
2
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,...
6
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...
3
kaleeswaran
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...
1
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...
0
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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
1
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...
0
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...
0
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...
0
Oralloy
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,...
0
jinu1996
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...
0
tracyyun
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...
0
agi2029
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,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.