从 XML 字符串中获取内部值


get inner value from xml string

大家好,我如何从下面的 xml 中提取金额值?

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

我目前正在使用以下

$lastEvent = balance->amount->value;
格式化

的XML如下所示:

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

如您所见,value 不是一个单独的节点,因此您必须按如下方式访问它(假设您使用 SimpleXML 进行解析):

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

演示!