Serebos
Новичок
Всем привет. Разбираюсь с модулем SimpleXML. Столкнулся с проблемой доступа к отдельным элементам.
Подключил файл
в нем, корневой элемент содержит 25 дочерних. Вот часть структуры xml файла
Запрос
Выводит корректное знание в браузере.
Когда подставляю другое значение элемента, например 2 или 3 в title_original - ничего не выводит.
Подскажите, пожалуйста, в чем причина этого поведения? Спасибо.
Подключил файл
PHP:
$xml = simplexml_load_file("xml/movies.xml") or die("Error: Cannot create object");
XML:
SimpleXMLElement Object
(
[movie] => Array
(
[0] => SimpleXMLElement Object
(
[id] => 154054
[type] => movie
[title_russian] => Джой
[title_original] => Joy
[year] => 2015
[runtime] => 0
[poster] => SimpleXMLElement Object
(
[small] => SimpleXMLElement Object
(
[@attributes] => Array
(
[url] => http://c.cinemate.cc/media/m/4/5/154054/0.small.jpg
)
)
[medium] => SimpleXMLElement Object
(
[@attributes] => Array
(
[url] => http://c.cinemate.cc/media/m/4/5/154054/0.medium.jpg
)
)
[big] => SimpleXMLElement Object
(
[@attributes] => Array
(
[url] => http://c.cinemate.cc/media/m/4/5/154054/0.big.jpg
)
)
)
[url] => http://cinemate.cc/movie/154054/
[country] => SimpleXMLElement Object
(
[name] => США
)
[genre] => SimpleXMLElement Object
(
[name] => Array
(
[0] => биография
[1] => драма
[2] => комедия
)
)
[description] => Joy is the story of the title character, who rose to become founder and matriarch of a powerful family business dynasty.
)
[1] => SimpleXMLElement Object
(
[id] => 159513
[type] => movie
[title_russian] => Лазурный берег
[title_original] => By the Sea
[year] => 2015
[runtime] => 0
[poster] => SimpleXMLElement Object
(
[small] => SimpleXMLElement Object
(
[@attributes] => Array
(
[url] => http://c.cinemate.cc/media/m/3/1/159513/0.small.jpg
)
)
[medium] => SimpleXMLElement Object
(
[@attributes] => Array
(
[url] => http://c.cinemate.cc/media/m/3/1/159513/0.medium.jpg
)
)
[big] => SimpleXMLElement Object
(
[@attributes] => Array
(
[url] => http://c.cinemate.cc/media/m/3/1/159513/0.big.jpg
)
)
)
[url] => http://cinemate.cc/movie/159513/
[country] => SimpleXMLElement Object
(
[name] => США
)
[genre] => SimpleXMLElement Object
(
[name] => Array
(
[0] => драма
[1] => мелодрама
)
)
[description] => A couple tries to repair their marriage while staying at a hotel in France.
)
[2] => SimpleXMLElement Object
(
[id] => 157449
[type] => movie
[title_russian] => Защитник
[title_original] => Concussion
[year] => 2015
[runtime] => 0
[poster] => SimpleXMLElement Object
(
[small] => SimpleXMLElement Object
(
[@attributes] => Array
(
[url] => http://c.cinemate.cc/media/m/9/4/157449/0.small.jpg
)
)
[medium] => SimpleXMLElement Object
(
[@attributes] => Array
(
[url] => http://c.cinemate.cc/media/m/9/4/157449/0.medium.jpg
)
)
[big] => SimpleXMLElement Object
(
[@attributes] => Array
(
[url] => http://c.cinemate.cc/media/m/9/4/157449/0.big.jpg
)
)
)
[url] => http://cinemate.cc/movie/157449/
[country] => SimpleXMLElement Object
(
[name] => Array
(
[0] => Австралия
[1] => Великобритания
[2] => США
)
)
[genre] => SimpleXMLElement Object
(
[name] => Array
(
[0] => драма
[1] => спорт
)
)
[description] => In Pittsburgh, accomplished pathologist Dr. Bennet Omalu uncovers the truth about brain damage in football players who suffer repeated concussions in the course of normal play.
)
Код:
$xml_node = $xml->movie;
echo $xml_node->title_original[0];
или
echo $xml->movie->title_original[0];
Когда подставляю другое значение элемента, например 2 или 3 в title_original - ничего не выводит.
PHP:
$xml_node = $xml->movie;
echo $xml_node->title_original[2];