SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Evangelist tangledman's Avatar
    Join Date
    Sep 2005
    Location
    Puerto de Mazarron, Murcia, Spain
    Posts
    425
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    I am trying to parse an XML document, stuck on how to get child nodes into an array

    Hi Site pointers,

    I am try to parse an XML file.
    http://www.xml2u.com/Xml/Property%20...35_Default.xml

    The XML describes properties for sale. I am not sure how to access the images:

    Any help will be greatly appreciated.

    My code below successfully extracts the property details, but not the images.

    PHP Code:
    //property Sales Espana

    $xml_link "http://www.xml2u.com/Xml/Property%20Salespana_735/1335_Default.xml";

    //echo $xml_link;

    $xml simplexml_load_file($xml_link);

    // get agent id 
    foreach ($xml->Clients->Client->properties->Property as $Property) {
    $propertyid $Property->propertyid;
    $location $Property->Address->location;
    $street $Property->Address->street;
    $region $Property->Address->region;
    $country $Property->Address->country;
    $currency $Property->Price->currency;
    $price $Property->Price->price;
    $status $Property->Price->status;
    $propertyType $Property->Description->propertyType;
    $bedrooms $Property->Description->bedrooms;
    $fullBathrooms $Property->Description->fullBathrooms;
    $title $Property->Description->title;
    $description $Property->Description->description;
    $floorSize $Property->Description->FloorSize->floorSize;
    $floorSizeUnits $Property->Description->FloorSize->floorSizeUnits;
    $plotSize $Property->Description->PlotSize->plotSize;
    $plotSizeUnits $Property->Description->PlotSize->plotSizeUnits;
    $Feature1 $Property->Description->Features->Feature1;
    $Feature2 $Property->Description->Features->Feature2;
    $Feature3 $Property->Description->Features->Feature3;
    $Feature4 $Property->Description->Features->Feature4;
    $link $Property->link->dataSource;


        foreach(
    $Property->images as $images) {
            
    $image $images-> image;
            
        }
    //$plotSizeUnits= $Features->PlotSize->plotSizeUnits;
        
        
    $output $output.$propertyid.'<br />'.
        
    $location.'<br />'.
        
    $street.'<br />'.
        
    $region.'<br />'.
        
    $currency.'<br />'.
        
    $price.'<br />'.
        
    $status.'<br />'.
        
    $propertyType.'<br />'.
        
    $bedrooms .'<br />'.
        
    $fullBathrooms.'<br />'.
        
    $title.'<br />'.
        
    $description.'<br />'.
        
    $floorSize.'<br />'.
        
    $floorSizeUnits.'<br />'.
        
    $plotSize.'<br />'.
        
    $plotSizeUnits.'<br />'.
        
    $Feature1 .'<br />'.
        
    $Feature2.'<br />'.
        
    $Feature3.'<br />'.
        
    $Feature4.'<br />'.
        
    $link.'<br />'.
        
    $image.'<br />'
        
    ;



  2. #2
    @php.net Salathe's Avatar
    Join Date
    Dec 2004
    Location
    Edinburgh
    Posts
    1,396
    Mentioned
    54 Post(s)
    Tagged
    0 Thread(s)
    The images XML is like:

    Code XML:
    <images>
     <image number="1">
      <image>http://www.propertysalespana.com…</image>
     </image>
     <image number="2">
      <image>http://www.propertysalespana.com…</image>
     </image></images>

    Because of this, you want to foreach over $Property->images->image (the image elements with number attributes).

    PHP Code:
    foreach($Property->images->image as $images) { 
    Salathe
    Software Developer and PHP Manual Author.

  3. #3
    SitePoint Evangelist tangledman's Avatar
    Join Date
    Sep 2005
    Location
    Puerto de Mazarron, Murcia, Spain
    Posts
    425
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks dude.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •