Forum Moderators: open

Message Too Old, No Replies

xml response from usps servers need to translate to php

xml response from usps servers

         

goldencrown

2:18 am on Feb 13, 2005 (gmt 0)

10+ Year Member



i need some help with tranlating some xml.. this is a response from the usps servers. what i want to do is get the info in between <Toaddress \> and set it to varable $toaddress. then i can use it any way i wan
't. I am very new to this. but i also want to learn from this as well.the language i am working with is php so i will need a php solution
<?xml version="1.0"?>
- <DeliveryConfirmationV3.0Response>
<DeliveryConfirmationNumber>420871029101805213907586457089</DeliveryConfirmationNumber>
<DeliveryConfirmationLabel>JVBERi0xLjINCjUgMC</DeliveryConfirmationLabel>
<ToName>chris Morales</ToName>
<ToFirm>GOLDEN</ToFirm>
<ToAddress1 />
<ToAddress2>1220 southwest</ToAddress2>
<ToCity>ALBUQUERQUE</ToCity>
<ToState>NM</ToState>
<ToZip5>87102</ToZip5>
<ToZip4>1081</ToZip4>
<Postnet>87102108107</Postnet>
</DeliveryConfirmationV3.0Response>

vinyljunkie

2:49 am on Feb 15, 2005 (gmt 0)

10+ Year Member



I'm a little confused by your message, because it looks like you're missing some tags in your xml file. Are you looking to get the value between <ToAddress1> and </ToAddress1> (that isn't formed correctly in what you posted) or just all the elements in each of the address fields?

Let's say you just wanted to retrieve the value between here:


<ToAddress2>1220 southwest</ToAddress2>

and place it in a PHP variable. Here's how you would do it:


preg_match("¦<ToAddress2>(.*)</ToAddress2>¦sU", $xmlfile, $item);

That places your PHP variable in $item[1]

Hope this helps.