php + XPath ile metin olarak düğüm değerini elde

2 Cevap php

How can I just obtain the string value of a Xml node using xpath in PHP? I RTFM but there is more complicated situations, using foreach I want just my node text. XML:

<ValCurs Date="00.00.0000" name="Official exchange rate">
<Valute ID="47">
  <NumCode>978</NumCode>
  <CharCode>EUR</CharCode>
  <Nominal>1</Nominal>
  <Name>Euro</Name>
  <Value>17.4619</Value>
</Valute>
</ValCurs>

Ben ne:

$xmlToday = simplexml_load_file($urlToday);
$EurToday = $xmlToday->xpath("/ValCurs/Valute[@ID='47']/Value");

$EurToday = array(1) { [0]=>  object(SimpleXMLElement)#3 (1)
                         { [0]=>  string(7) "17.4619" } }

Ben sadece değer gerekir. Bir yüzen değer olarak.

2 Cevap

XPath Examples, w3schools.com

Tüm fiyatları seçiniz: bölümüne bakın

/bookstore/book/price/text()

text () sizin için ne arıyorsanız olsun gibi görünüyor. PHP eşdeğer Dolayısıyla SaveXML () gibi görünüyor:

$EurToday = (float) $xmlToday->xpath("/ValCurs/Valute[@ID='47']/Value/savexml()");