Ниже описана функция php для получения xml атрибута для одиночного тега serie. Засовываем Узел xml и название атрибута
1 2 3 4 5 |
function xml_attribute($object, $attribute) { if(isset($object[$attribute])) return (string) $object[$attribute]; } |
Вот использование функции получения атрибута xml. Как бонус- функция скачки через curl.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
//функция скачки страницы xml через curl . получаем xml Объект. function download_page($path){ $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,$path); curl_setopt($ch, CURLOPT_FAILONERROR,1); curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1); curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); curl_setopt($ch, CURLOPT_TIMEOUT, 60); $retValue = curl_exec($ch); $data= curl_getinfo ($ch); // print_r($data); // смотрим статусы для отладки - http_code curl_close($ch); return $retValue; } $url='wash urliche'; $book_XML = new SimpleXMLElement(download_page($url))); // получение name $name= xml_attribute($xml->products->product[0]->serie, 'name'); |
Вот сама xml.
1 2 3 4 5 6 7 8 9 10 11 12 13 |
This XML file does not appear to have any style information associated with it. The document tree is shown below. <result> <pages> <items>6</items> <current>1</current> <all>1</all> </pages> <products> <product> <serie propname="Серия" name="Интеллектуально и Лучшее" id="ыыыыыыыы" code="ввввввв" dddd="ssss"> </product> </products> </result> |