Warning: Cannot use a scalar value as an array in /home/admin/public_html/forum/include/fm.class.php on line 757

Warning: Invalid argument supplied for foreach() in /home/admin/public_html/forum/include/fm.class.php on line 770
Форумы портала PHP.SU :: Версия для печати :: Не могу разобрать xml файл
Форумы портала PHP.SU » » XML и его обработка » Не могу разобрать xml файл

Страниц (1): [1]
 

1. tovarz - 03 Июня, 2016 - 21:05:26 - перейти к сообщению
Вот текст xml файла catalog.xml

CODE (htmlphp):
скопировать код в буфер обмена
  1. <?xml version="1.0"?>
  2. <catalog version="1.0" date="2016-06-03 03:20"><shop>
  3. <name>111111111111</name>
  4. <currencies>
  5.         <currency id="RUR" rate="1" />
  6.         <currency id="USD" rate="42" />
  7.         <currency id="EUR" rate="53" />
  8. </currencies>
  9. </shop></catalog>


Вот код php файла
PHP:
скопировать код в буфер обмена
  1. $xml = simplexml_load_file('catalog.xml');
  2. foreach ($xml as $info) {
  3. echo $info;
  4. }


Выводит пустое окно.
print_r($xml); выводит вот что:
SimpleXMLElement Object ( [@attributes] => Array ( [version] => 1.0 [date] => 2016-06-03 03:20 ) [shop] => SimpleXMLElement Object ( [name] => 111111111111 [currencies] => SimpleXMLElement Object ( [currency] => Array ( [0] => SimpleXMLElement Object ( [@attributes] => Array ( [id] => RUR [rate] => 1 ) ) [1] => SimpleXMLElement Object ( [@attributes] => Array ( [id] => USD [rate] => 42 ) ) [2] => SimpleXMLElement Object ( [@attributes] => Array ( [id] => EUR [rate] => 53 ) ) ) ) ) )

Не пойму, как мне вывести например все значения в теге currencies хмл файла?
2. Bio man - 03 Июня, 2016 - 22:39:45 - перейти к сообщению
Открываешь документацию и читаешь
http://php.net/manual/ru/functio...ml-load-file.php
http://php.net/manual/ru/class.s...lexmlelement.php
http://php.net/manual/ru/simplex...ent.children.php

 

Powered by ExBB FM 1.0 RC1