2014-02-02 5 views
0

Я пытаюсь сделать это на 3 часа, поэтому я буду признателен за любую помощь. Мне нужно проанализировать xml ниже и извлечь «заголовок», «описание», «телефон», «адрес», «цена», «картинки», «атрибуты». Мне удалось получить название, описание и телефон.Как анализировать xml с помощью xpath и извлекать массив элементов?

Я не могу получить адрес (местоположение) широты и долготы по отдельности. Я получаю -1.3054552.7008 вместо широты: -1.3054, долгота: 552.7008.

Я не знаю, как извлечь фотографии. Это должен быть массив.

Я не знаю, как извлечь атрибуты. Это должен быть массив.

Вот код, у меня есть:

$adXml = file_get_contents('ad.xml'); 

$dom = new DOMDocument(); 
$dom->loadXml($adXml); 
$xpath = new DOMXpath($dom); 
$xpath->registerNamespace('ad', 'http://www.domainclassifiedsgroup.com/schema/ad/v1'); 
$xpath->registerNamespace('attribute', 'http://www.domainclassifiedsgroup.com/schema/attribute/v1'); 
$xpath->registerNamespace('pic', 'http://www.domainclassifiedsgroup.com/schema/picture/v1'); 
$xpath->registerNamespace('location', 'http://www.domainclassifiedsgroup.com/schema/location/v1'); 

#$ads = $xpath->evaluate('/ad:ad/ad:ad', NULL, FALSE); 

$title = $xpath->evaluate('string(ad:title)', NULL, FALSE); 
$description = $xpath->evaluate('string(ad:description)', NULL, FALSE); 
$phone = $xpath->evaluate('string(ad:phone)', NULL, FALSE); 

//the price is a kind of array so we ened to remove GBP 
$price = $xpath->evaluate('string(ad:price)', NULL, FALSE); 
$price = str_replace('GBP', '', $price); 

//$pictures = $xpath->evaluate('string(pic:pictures)', NULL, FALSE); 
$pictures = '?'; 
$attributes = '?'; 
$address = $xpath->evaluate('string(ad:ad-address)', NULL, FALSE); // why is not array ? 

XML-ниже

<?xml version="1.0" encoding="UTF-8" standalone="yes"?> 
<ad:ad xmlns:types="http://www.domainclassifiedsgroup.com/schema/types/v1" xmlns:cat="http://www.domainclassifiedsgroup.com/schema/category/v1" xmlns:loc="http://www.domainclassifiedsgroup.com/schema/location/v1" xmlns:ad="http://www.domainclassifiedsgroup.com/schema/ad/v1" xmlns:feat="http://www.domainclassifiedsgroup.com/schema/feature/v1" xmlns:attr="http://www.domainclassifiedsgroup.com/schema/attribute/v1" xmlns:pic="http://www.domainclassifiedsgroup.com/schema/picture/v1" xmlns:user="http://www.domainclassifiedsgroup.com/schema/user/v1" xmlns:rate="http://www.domainclassifiedsgroup.com/schema/rate/v1" xmlns:reply="http://www.domainclassifiedsgroup.com/schema/reply/v1" xmlns:feed="http://www.domainclassifiedsgroup.com/schema/feed/v1" xmlns:order="http://www.domainclassifiedsgroup.com/schema/order/v1" xmlns:payment="http://www.domainclassifiedsgroup.com/schema/payment/v1" locale="en_GB" version="1.17" id="1047060901"> 
    <ad:price> 
    <types:currency-iso-code> 
     <types:value localized-label="£">GBP</types:value> 
    </types:currency-iso-code> 
    <types:amount>17300</types:amount> 
    </ad:price> 
    <ad:title>BMW 330d M Sport Highline Coupe Black Diesel Auto + RED LEATHER</ad:title> 
    <ad:description>2009 (59-reg). Sapphire black metallic. Coral red Dakota leather, electric adjustable seats with memory, heated seats, sport seats, USB interface for iPod, steering wheel gear shift, Angel daytime running lights, Xenon headlights, 19 inch Double spoke alloy wheels, fine brushed aluminium interior trim, power fold mirrors, M Sport Aerodynamic bodystyling package, loudspeaker audio upgrade, enhanced Bluetooth, climate control, cruise control, trip computer, ISOFIX child seat anchors, park sensors, split folding rear seats, remote locking alarm. FSH. 

Passenger Airbag; Air Conditioning; Premium Sound System; AM/FM Stereo; Xenon headlights; Climate Control; Alloy Wheels; Full Service History; Alarm; Tilt Steering Wheel; Central Locking; Anti-Lock Brakes (ABS); CD Player; Driver Airbag; Electric Windows; Power-assisted Steering (PAS); Electric heated seats; Safety Belt Pretensioners; Parking Sensors; V5 Registration Document; Cruise Control; Leather Seats; Immobiliser; Electric Adjustable Seats; Side Airbags; Rear seat belts; Electronic Stability Program (ESP) </ad:description> 
    <ad:ad-address> 
    <types:longitude>-1.30545</types:longitude> 
    <types:latitude>52.7008</types:latitude> 
    </ad:ad-address> 
    <ad:search-distance> 
    <ad:display-distance></ad:display-distance> 
    </ad:search-distance> 
    <ad:ad-status> 
    <ad:value>ACTIVE</ad:value> 
    </ad:ad-status> 
    <ad:email>EXIST</ad:email> 
    <ad:user-id>3463331380</ad:user-id> 
    <ad:poster-ip-address/> 
    <ad:phone>01530249618</ad:phone> 
    <ad:modification-date-time>2014-02-02T03:02:41.000Z</ad:modification-date-time> 
    <ad:start-date-time>2014-02-02T03:02:41.000Z</ad:start-date-time> 
    <feat:features-active> 
    <feat:feature-active display="true" name="AD_INSERTION" group="standard"/> 
    </feat:features-active> 
    <cat:category id="10303"> 
    <cat:id-name>bmw</cat:id-name> 
    <cat:localized-name>BMW</cat:localized-name> 
    <cat:categoriesTree/> 
    </cat:category> 
    <loc:locations> 
    <loc:location id="10000393"> 
     <loc:id-name>england</loc:id-name> 
     <loc:localized-name>England</loc:localized-name> 
     <loc:parent-id/> 
     <loc:location-breadcrumb/> 
    </loc:location> 
    <loc:location id="10000392"> 
     <loc:id-name>uk</loc:id-name> 
     <loc:localized-name>United Kingdom</loc:localized-name> 
     <loc:parent-id/> 
     <loc:location-breadcrumb/> 
    </loc:location> 
    <loc:location id="11000025"> 
     <loc:id-name>leicestershire</loc:id-name> 
     <loc:localized-name>Leicestershire</loc:localized-name> 
     <loc:parent-id/> 
     <loc:location-breadcrumb/> 
    </loc:location> 
    </loc:locations> 
    <ad:neighborhood></ad:neighborhood> 
    <attr:attributes> 
    <attr:attribute localized-label="Fuel type" type="ENUM" name="vehicle_fuel_type"> 
     <attr:value localized-label="Diesel">diesel</attr:value> 
    </attr:attribute> 
    <attr:attribute localized-label="Year" type="INTEGER" name="vehicle_registration_year"> 
     <attr:value localized-label="2009">2009</attr:value> 
    </attr:attribute> 
    <attr:attribute localized-label="Body type" type="ENUM" name="vehicle_body_type"> 
     <attr:value localized-label="Coupe">coupe</attr:value> 
    </attr:attribute> 
    <attr:attribute localized-label="Model" type="STRING" name="vehicle_model"> 
     <attr:value>330</attr:value> 
    </attr:attribute> 
    <attr:attribute localized-label="Colour" type="STRING" name="vehicle_colour"> 
     <attr:value>Black</attr:value> 
    </attr:attribute> 
    <attr:attribute localized-label="Seller type" type="ENUM" name="seller_type"> 
     <attr:value localized-label="Trade">trade</attr:value> 
    </attr:attribute> 
    <attr:attribute localized-label="Mileage" type="LONG" name="vehicle_mileage"> 
     <attr:value>65000</attr:value> 
    </attr:attribute> 
    <attr:attribute localized-label="Transmission" type="ENUM" name="vehicle_transmission"> 
     <attr:value localized-label="Automatic">automatic</attr:value> 
    </attr:attribute> 
    <attr:attribute localized-label="Make" type="ENUM" name="vehicle_make"> 
     <attr:value localized-label="BMW">bmw</attr:value> 
    </attr:attribute> 
    <attr:attribute localized-label="Engine size" type="LONG" name="vehicle_engine_size"> 
     <attr:value>2993</attr:value> 
    </attr:attribute> 
    </attr:attributes> 
    <ad:link rel="self" href="https://iphone-api.zmbtree.com/api/ads/1047060901"/> 
    <ad:link rel="self-user" href="https://iphone-api.zmbtree.com/api/users/3463331380/ads/1047060901"/> 
    <ad:link rel="self-public-website" href="http://www.zmbtree.com/p/cars-vans-motorbikes/bmw-330d-m-sport-highline-coupe-black-diesel-auto-red-leather/1047060901"/> 
    <pic:pictures> 
    <pic:picture> 
     <pic:link rel="extrabig" href="http://i.domainimg.com/00/s/NTMxWDgwMA==/z/C-QAAMXQWzNSeR-h/$(KGrHqJHJFEFJ0Ie)pzWBSeR-hK5zw~~48_80.JPG"/> 
     <pic:link rel="preview" href="http://i.domainimg.com/00/s/NTMxWDgwMA==/z/C-QAAMXQWzNSeR-h/$(KGrHqJHJFEFJ0Ie)pzWBSeR-hK5zw~~48_81.JPG"/> 
     <pic:link rel="big" href="http://i.domainimg.com/00/s/NTMxWDgwMA==/z/C-QAAMXQWzNSeR-h/$(KGrHqJHJFEFJ0Ie)pzWBSeR-hK5zw~~48_79.JPG"/> 
     <pic:link rel="thumb" href="http://i.domainimg.com/00/s/NTMxWDgwMA==/z/C-QAAMXQWzNSeR-h/$(KGrHqJHJFEFJ0Ie)pzWBSeR-hK5zw~~48_78.JPG"/> 
     <pic:link rel="moreadsthumb" href="http://i.domainimg.com/00/s/NTMxWDgwMA==/z/C-QAAMXQWzNSeR-h/$(KGrHqJHJFEFJ0Ie)pzWBSeR-hK5zw~~48_77.JPG"/> 
    </pic:picture> 
    <pic:picture> 
     <pic:link rel="extrabig" href="http://i.domainimg.com/00/s/NTMxWDgwMA==/z/rwcAAOxyLN9SeR-h/$(KGrHqNHJEIFJbuUsB1BBSeR-hFuC!~~48_80.JPG"/> 
     <pic:link rel="preview" href="http://i.domainimg.com/00/s/NTMxWDgwMA==/z/rwcAAOxyLN9SeR-h/$(KGrHqNHJEIFJbuUsB1BBSeR-hFuC!~~48_81.JPG"/> 
     <pic:link rel="big" href="http://i.domainimg.com/00/s/NTMxWDgwMA==/z/rwcAAOxyLN9SeR-h/$(KGrHqNHJEIFJbuUsB1BBSeR-hFuC!~~48_79.JPG"/> 
     <pic:link rel="thumb" href="http://i.domainimg.com/00/s/NTMxWDgwMA==/z/rwcAAOxyLN9SeR-h/$(KGrHqNHJEIFJbuUsB1BBSeR-hFuC!~~48_78.JPG"/> 
     <pic:link rel="moreadsthumb" href="http://i.domainimg.com/00/s/NTMxWDgwMA==/z/rwcAAOxyLN9SeR-h/$(KGrHqNHJEIFJbuUsB1BBSeR-hFuC!~~48_77.JPG"/> 
    </pic:picture> 
    <pic:picture> 
     <pic:link rel="extrabig" href="http://i.domainimg.com/00/s/NTMxWDgwMA==/z/DKgAAOxyzi9SeR-h/$T2eC16F,!yEFI9U4HtWeBSeR-h!PI!~~48_80.JPG"/> 
     <pic:link rel="preview" href="http://i.domainimg.com/00/s/NTMxWDgwMA==/z/DKgAAOxyzi9SeR-h/$T2eC16F,!yEFI9U4HtWeBSeR-h!PI!~~48_81.JPG"/> 
     <pic:link rel="big" href="http://i.domainimg.com/00/s/NTMxWDgwMA==/z/DKgAAOxyzi9SeR-h/$T2eC16F,!yEFI9U4HtWeBSeR-h!PI!~~48_79.JPG"/> 
     <pic:link rel="thumb" href="http://i.domainimg.com/00/s/NTMxWDgwMA==/z/DKgAAOxyzi9SeR-h/$T2eC16F,!yEFI9U4HtWeBSeR-h!PI!~~48_78.JPG"/> 
     <pic:link rel="moreadsthumb" href="http://i.domainimg.com/00/s/NTMxWDgwMA==/z/DKgAAOxyzi9SeR-h/$T2eC16F,!yEFI9U4HtWeBSeR-h!PI!~~48_77.JPG"/> 
    </pic:picture> 
    <pic:picture> 
     <pic:link rel="extrabig" href="http://i.domainimg.com/00/s/NTMxWDgwMA==/z/p-QAAOxypNtSeR-h/$T2eC16VHJG8E9nyfnfl1BSeR-hFy)!~~48_80.JPG"/> 
     <pic:link rel="preview" href="http://i.domainimg.com/00/s/NTMxWDgwMA==/z/p-QAAOxypNtSeR-h/$T2eC16VHJG8E9nyfnfl1BSeR-hFy)!~~48_81.JPG"/> 
     <pic:link rel="big" href="http://i.domainimg.com/00/s/NTMxWDgwMA==/z/p-QAAOxypNtSeR-h/$T2eC16VHJG8E9nyfnfl1BSeR-hFy)!~~48_79.JPG"/> 
     <pic:link rel="thumb" href="http://i.domainimg.com/00/s/NTMxWDgwMA==/z/p-QAAOxypNtSeR-h/$T2eC16VHJG8E9nyfnfl1BSeR-hFy)!~~48_78.JPG"/> 
     <pic:link rel="moreadsthumb" href="http://i.domainimg.com/00/s/NTMxWDgwMA==/z/p-QAAOxypNtSeR-h/$T2eC16VHJG8E9nyfnfl1BSeR-hFy)!~~48_77.JPG"/> 
    </pic:picture> 
    <pic:picture> 
     <pic:link rel="extrabig" href="http://i.domainimg.com/00/s/NTMxWDgwMA==/z/AhMAAOxy4t1SeR~d/$T2eC16h,!z!FJ4!MUtWSBSeR+d8SCw~~48_80.JPG"/> 
     <pic:link rel="preview" href="http://i.domainimg.com/00/s/NTMxWDgwMA==/z/AhMAAOxy4t1SeR~d/$T2eC16h,!z!FJ4!MUtWSBSeR+d8SCw~~48_81.JPG"/> 
     <pic:link rel="big" href="http://i.domainimg.com/00/s/NTMxWDgwMA==/z/AhMAAOxy4t1SeR~d/$T2eC16h,!z!FJ4!MUtWSBSeR+d8SCw~~48_79.JPG"/> 
     <pic:link rel="thumb" href="http://i.domainimg.com/00/s/NTMxWDgwMA==/z/AhMAAOxy4t1SeR~d/$T2eC16h,!z!FJ4!MUtWSBSeR+d8SCw~~48_78.JPG"/> 
     <pic:link rel="moreadsthumb" href="http://i.domainimg.com/00/s/NTMxWDgwMA==/z/AhMAAOxy4t1SeR~d/$T2eC16h,!z!FJ4!MUtWSBSeR+d8SCw~~48_77.JPG"/> 
    </pic:picture> 
    <pic:picture> 
     <pic:link rel="extrabig" href="http://i.domainimg.com/00/s/NTMxWDgwMA==/z/MjkAAOxy3NBSeR~e/$(KGrHqN,!rkFJURnmyKpBSeR+eQ7Rg~~48_80.JPG"/> 
     <pic:link rel="preview" href="http://i.domainimg.com/00/s/NTMxWDgwMA==/z/MjkAAOxy3NBSeR~e/$(KGrHqN,!rkFJURnmyKpBSeR+eQ7Rg~~48_81.JPG"/> 
     <pic:link rel="big" href="http://i.domainimg.com/00/s/NTMxWDgwMA==/z/MjkAAOxy3NBSeR~e/$(KGrHqN,!rkFJURnmyKpBSeR+eQ7Rg~~48_79.JPG"/> 
     <pic:link rel="thumb" href="http://i.domainimg.com/00/s/NTMxWDgwMA==/z/MjkAAOxy3NBSeR~e/$(KGrHqN,!rkFJURnmyKpBSeR+eQ7Rg~~48_78.JPG"/> 
     <pic:link rel="moreadsthumb" href="http://i.domainimg.com/00/s/NTMxWDgwMA==/z/MjkAAOxy3NBSeR~e/$(KGrHqN,!rkFJURnmyKpBSeR+eQ7Rg~~48_77.JPG"/> 
    </pic:picture> 
    <pic:picture> 
     <pic:link rel="extrabig" href="http://i.domainimg.com/00/s/NTMxWDgwMA==/z/x9YAAOxyXDhSeR~e/$(KGrHqFHJB8FJvCbFiKMBSeR+elk(Q~~48_80.JPG"/> 
     <pic:link rel="preview" href="http://i.domainimg.com/00/s/NTMxWDgwMA==/z/x9YAAOxyXDhSeR~e/$(KGrHqFHJB8FJvCbFiKMBSeR+elk(Q~~48_81.JPG"/> 
     <pic:link rel="big" href="http://i.domainimg.com/00/s/NTMxWDgwMA==/z/x9YAAOxyXDhSeR~e/$(KGrHqFHJB8FJvCbFiKMBSeR+elk(Q~~48_79.JPG"/> 
     <pic:link rel="thumb" href="http://i.domainimg.com/00/s/NTMxWDgwMA==/z/x9YAAOxyXDhSeR~e/$(KGrHqFHJB8FJvCbFiKMBSeR+elk(Q~~48_78.JPG"/> 
     <pic:link rel="moreadsthumb" href="http://i.domainimg.com/00/s/NTMxWDgwMA==/z/x9YAAOxyXDhSeR~e/$(KGrHqFHJB8FJvCbFiKMBSeR+elk(Q~~48_77.JPG"/> 
    </pic:picture> 
    <pic:picture> 
     <pic:link rel="extrabig" href="http://i.domainimg.com/00/s/NTMxWDgwMA==/z/MjUAAOxy3NBSeR~d/$(KGrHqMOKpIFJ30nYMeqBSeR+e!FDg~~48_80.JPG"/> 
     <pic:link rel="preview" href="http://i.domainimg.com/00/s/NTMxWDgwMA==/z/MjUAAOxy3NBSeR~d/$(KGrHqMOKpIFJ30nYMeqBSeR+e!FDg~~48_81.JPG"/> 
     <pic:link rel="big" href="http://i.domainimg.com/00/s/NTMxWDgwMA==/z/MjUAAOxy3NBSeR~d/$(KGrHqMOKpIFJ30nYMeqBSeR+e!FDg~~48_79.JPG"/> 
     <pic:link rel="thumb" href="http://i.domainimg.com/00/s/NTMxWDgwMA==/z/MjUAAOxy3NBSeR~d/$(KGrHqMOKpIFJ30nYMeqBSeR+e!FDg~~48_78.JPG"/> 
     <pic:link rel="moreadsthumb" href="http://i.domainimg.com/00/s/NTMxWDgwMA==/z/MjUAAOxy3NBSeR~d/$(KGrHqMOKpIFJ30nYMeqBSeR+e!FDg~~48_77.JPG"/> 
    </pic:picture> 
    </pic:pictures> 
    <ad:visible-on-map>true</ad:visible-on-map> 
    <ad:poster-contact-email>EXIST</ad:poster-contact-email> 
    <ad:poster-contact-name/> 
</ad:ad> 

Update: Попытка получить изображения с помощью

$pictures = $xml->xpath("//pic:pictures/pic:picture"); 

foreach ($pictures as $picture) { 

    $pic = (string)$picture->xpath("pic:link/@extrabig")[0]; 

    print_r($pic); 
} 

не работает.

ответ

-1

Это адская XML ...

Вот код, используя simplexml и xpath. Извините, я не так много в DOM. Для этого примера требуется PHP> = 5.4.

$xml = simplexml_load_string($x); // assume XML in $x 

$title = (string)$xml->xpath("//ad:ad/ad:title")[0]; 
$price = (string)$xml->xpath("//ad:ad/ad:price/types:amount")[0]; 
$attributes = $xml->xpath("//attr:attributes/attr:attribute"); 

echo $title . PHP_EOL; 
echo $price. PHP_EOL; 

foreach ($attributes as $a) { 
    $label = (string)$a->xpath("@localized-label")[0]; 
    $value = (string)$a->xpath("./attr:value")[0]; 
    echo "$label: $value" . PHP_EOL; 
} 

Вы можете получить доступ к другим узлам в соответствии с этими примерами.

Смотреть это работает: https://eval.in/97091

Комментарии:

  • использует XPath без регистрации пространств имен.
  • (string) = заливке XPATH-результаты в строку вместо того, чтобы объекты, как результаты
  • ...)[0]; = массив разыменования, требует PHP> = 5,4

UPDATE: получить @rel='extrabig'@href из <pic:link> узлов:

$pictures = $xml->xpath("//pic:pictures/pic:picture/pic:link[@rel = 'extrabig']/@href"); 
$pictures = array_map('strval', $pictures); // converts every element to string 
foreach ($pictures as $pic) echo $pic . PHP_EOL; 
+0

спасибо большое! Это выглядит великолепно! Жаль, что кто-то проголосовал за это. Тем не менее я изо всех сил пытаюсь получить изображения. Меня интересуют только экстрабиги. Вот что я пробовал $ pictures = $ xml-> xpath ("// pic: pictures/pic: picture"); foreach ($ picture as $ picture) { $ pic = (string) $ picture-> xpath ("pic: link/@ extrabig") [0]; print_r ($ pic); } –

+0

почему -1, пожалуйста, объясните – michi

+0

@ Theuserwithnohat см. Мое обновление! – michi

1

Если вы выбрали элемент в xpath, используя string(), number() или boolean(), он будет отличать n ode значение этого элемента. Это означает весь текстовый контент внутри этого элемента и его потомков.

Так что, если вы используете выражение string(ad:ad-address), оно возвращает содержимое обоих типов дочерних узлов: долгота и типы: широта. Чтобы их разделить, вам нужно использовать отдельные выражения для получения значений долготы/широты.

$dom = new DOMDocument(); 
$dom->loadXml($xml); 
$xpath = new DOMXpath($dom); 
$xpath->registerNamespace('ad', 'http://www.domainclassifiedsgroup.com/schema/ad/v1'); 
$xpath->registerNamespace('types', 'http://www.domainclassifiedsgroup.com/schema/types/v1'); 

var_dump(
    [ 
    'lng' => $xpath->evaluate('number(/ad:ad/ad:ad-address[1]/types:longitude)', NULL, FALSE), 
    'lat' => $xpath->evaluate('number(/ad:ad/ad:ad-address[1]/types:latitude)', NULL, FALSE) 
    ] 
); 

Выход:

array(2) { 
    ["lng"]=> 
    float(-1.30545) 
    ["lat"]=> 
    float(52.7008) 
} 

Если вы хотите обрабатывать несколько элементов вы запрашиваете список первым, итерацию и использовать выражение с узлом контекста. Контекстный узел - это второй аргумент метода оценки(). Если вы хотите, чтобы атрибуты/контент из элемента, который вы повторяете, вы можете использовать только что прочитанные с помощью getAttribute() или $ nodeValue.

$dom = new DOMDocument(); 
$dom->loadXml($xml); 
$xpath = new DOMXpath($dom); 
$xpath->registerNamespace('ad', 'http://www.domainclassifiedsgroup.com/schema/ad/v1'); 
$xpath->registerNamespace('pic', 'http://www.domainclassifiedsgroup.com/schema/picture/v1'); 

$result = []; 
$nodes = $xpath->evaluate('/ad:ad/pic:pictures/pic:picture', NULL, FALSE); 
foreach ($nodes as $node) { 
    $row = []; 
    foreach ($xpath->evaluate('pic:link', $node, FALSE) as $linkNode) { 
    $row[$linkNode->getAttribute('rel')] = $linkNode->getAttribute('href'); 
    } 
    $result[] = $row; 
} 

var_dump($result); 

Выход:

array(8) { 
    [0]=> 
    array(5) { 
    ["extrabig"]=> 
    string(102) "http://i.domainimg.com/00/s/NTMxWDgwMA==/z/C-QAAMXQWzNSeR-h/$(KGrHqJHJFEFJ0Ie)pzWBSeR-hK5zw~~48_80.JPG" 
    ["preview"]=> 
    string(102) "http://i.domainimg.com/00/s/NTMxWDgwMA==/z/C-QAAMXQWzNSeR-h/$(KGrHqJHJFEFJ0Ie)pzWBSeR-hK5zw~~48_81.JPG" 
    ["big"]=> 
    string(102) "http://i.domainimg.com/00/s/NTMxWDgwMA==/z/C-QAAMXQWzNSeR-h/$(KGrHqJHJFEFJ0Ie)pzWBSeR-hK5zw~~48_79.JPG" 
    ["thumb"]=> 
    string(102) "http://i.domainimg.com/00/s/NTMxWDgwMA==/z/C-QAAMXQWzNSeR-h/$(KGrHqJHJFEFJ0Ie)pzWBSeR-hK5zw~~48_78.JPG" 
    ["moreadsthumb"]=> 
    string(102) "http://i.domainimg.com/00/s/NTMxWDgwMA==/z/C-QAAMXQWzNSeR-h/$(KGrHqJHJFEFJ0Ie)pzWBSeR-hK5zw~~48_77.JPG" 
    } 
    [1]=> ... 
0
here is an alternative to xpath if you need it asap. 

<?php 

    $path = @file_get_contents('ad.xml'); 
    $xml = @simplexml_load_string($path); 
    $namespaces = $xml->getNameSpaces(true); 

    $ad = $xml->children($namespaces['ad']); 
    $description = (string)$ad->description; 
    echo $description; 

    $title = (string)$ad->title; 
    echo $title; 

    $address = $ad->{'ad-address'}->children($namespaces['types']); 
    echo $address->longitude; 
    echo $address->latitude; 

    $phone = (string)$ad->phone; 
    echo $phone; 

    $price = $ad->price->children($namespaces['types']); 
    echo $price; 

    $photos = $xml->children($namespaces['pic']); 
    $pictures = $photos->children('pic'); 

    foreach($photos->pictures as $pictures) 
    { 
     foreach($pictures as $photo) 
     { 
      foreach ($photo->link as $link) 
      { 
       $att = $link->attributes(); 
       if ($att['rel'] == 'extrabig') 
       { 
        echo $att['href']; 
       } 
      } 
     } 
    } 

    ?> 

Следующий код выводит следующее. Это была спешка. Я уверен, что вы можете реорганизовать его и заставить его анализировать канал динамически.

title: BMW 330d M Sport Highline Coupe Black Diesel Auto + RED LEATHER 
description: 2009 (59-reg). Sapphire black metallic. Coral red Dakota leather, electric adjustable seats with memory, heated seats, sport seats, USB interface for iPod, steering wheel gear shift, Angel daytime running lights, Xenon headlights, 19 inch Double spoke alloy wheels, fine brushed aluminium interior trim, power fold mirrors, M Sport Aerodynamic bodystyling package, loudspeaker audio upgrade, enhanced Bluetooth, climate control, cruise control, trip computer, ISOFIX child seat anchors, park sensors, split folding rear seats, remote locking alarm. FSH. Passenger Airbag; Air Conditioning; Premium Sound System; AM/FM Stereo; Xenon headlights; Climate Control; Alloy Wheels; Full Service History; Alarm; Tilt Steering Wheel; Central Locking; Anti-Lock Brakes (ABS); CD Player; Driver Airbag; Electric Windows; Power-assisted Steering (PAS); Electric heated seats; Safety Belt Pretensioners; Parking Sensors; V5 Registration Document; Cruise Control; Leather Seats; Immobiliser; Electric Adjustable Seats; Side Airbags; Rear seat belts; Electronic Stability Program (ESP) 
latitude: -1.30545 
longitude: 52.7008 
phone: 01530249618 
price: 
extrabig: http://i.domainimg.com/00/s/NTMxWDgwMA==/z/C-QAAMXQWzNSeR-h/$(KGrHqJHJFEFJ0Ie)pzWBSeR-hK5zw~~48_80.JPG 
extrabig: http://i.domainimg.com/00/s/NTMxWDgwMA==/z/rwcAAOxyLN9SeR-h/$(KGrHqNHJEIFJbuUsB1BBSeR-hFuC!~~48_80.JPG 
extrabig: http://i.domainimg.com/00/s/NTMxWDgwMA==/z/DKgAAOxyzi9SeR-h/$T2eC16F,!yEFI9U4HtWeBSeR-h!PI!~~48_80.JPG 
extrabig: http://i.domainimg.com/00/s/NTMxWDgwMA==/z/p-QAAOxypNtSeR-h/$T2eC16VHJG8E9nyfnfl1BSeR-hFy)!~~48_80.JPG 
extrabig: http://i.domainimg.com/00/s/NTMxWDgwMA==/z/AhMAAOxy4t1SeR~d/$T2eC16h,!z!FJ4!MUtWSBSeR+d8SCw~~48_80.JPG 
extrabig: http://i.domainimg.com/00/s/NTMxWDgwMA==/z/MjkAAOxy3NBSeR~e/$(KGrHqN,!rkFJURnmyKpBSeR+eQ7Rg~~48_80.JPG 
extrabig: http://i.domainimg.com/00/s/NTMxWDgwMA==/z/x9YAAOxyXDhSeR~e/$(KGrHqFHJB8FJvCbFiKMBSeR+elk(Q~~48_80.JPG 
extrabig: http://i.domainimg.com/00/s/NTMxWDgwMA==/z/MjUAAOxy3NBSeR~d/$(KGrHqMOKpIFJ30nYMeqBSeR+e!FDg~~48_80.JPG 
Смежные вопросы