-3

Hi guys how can I pull the amount value from the xml below?

<balance><amount value="1000" currencyCode="GBP" exponent="2" debitCreditIndicator="credit"/></balance>

I am currently using the following

$lastEvent = balance->amount->value;
user2811002
  • 55
  • 1
  • 7
  • Reading your code, I think you should first of all read about the error reporting and handling topic in PHP, perhaps this Q&A is a good introduction: [How to get useful error messages in PHP?](http://stackoverflow.com/q/845021/367456). Next to that you should make yourself comfortable with the wording in the XML domain, like *Element*, *Attribute*, *Value* etc., and perhaps first of all read the basic examples section in the PHP manual: [Basic SimpleXML usage](http://php.net/simplexml.examples-basic). That should lead you the way, for the Q you pose we have A already so I close-vote it. – hakre Oct 26 '13 at 18:32

1 Answers1

1

The formatted XML would look like:

<balance>
   <amount value="1000" currencyCode="GBP" exponent="2" debitCreditIndicator="credit" />
</balance>

As you can see, value is not a separate node, so you'll have to access it as below (assuming you're using SimpleXML to do the parsing):

$xml = simplexml_load_string($str); // $str contains your XML string
$lastEvent = $xml->amount['value'];

Demo!

Amal Murali
  • 75,622
  • 18
  • 128
  • 150