SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  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)

    Access a XML sub nodes when node is known.

    Happy Sunday Sitepointers.

    I want to pull the images into an array for a given property.

    How do I do that?


    XML sample:
    Code xml:
    <property>
    <id>1204468</id>
    <date>2013-04-09 14:28:44</date>
    <price>179995</price>
    <price_freq>sale</price_freq>
    <type>
    <en>villa</en>
    </type>
    <location_id>32721</location_id>
    <town>Mazarron</town>
    <postcode>30870</postcode>
    <province>Murcia</province>
    <location_detail></location_detail>
    <beds>3</beds>
    <baths>2</baths>
    <pool>1</pool>
    <images>
    <image id="7854941">
    <url>1204/1204468/7854941_large.jpg</url>
    <primary>1</primary>
    <title>
    <en></en>
    </title>
    </image>
    <image id="7854942">
    <url>1204/1204468/7854942_large.jpg</url>
    <title>
    <en></en>
    </title>
    </image>
    <image id="12052351">
    <url>1204/1204468/12052351_large.jpg</url>
    <title>
    <en></en>
    </title>
    </image>
    <image id="3986200">
    <url>1204/1204468/3986200_large.jpg</url>
    <title>
    <en></en>
    </title>
    </image>
    <image id="3986202">
    <url>1204/1204468/3986202_large.jpg</url>
    <title>
    <en></en>
    </title>
    </image>
    <image id="3986201">
    <url>1204/1204468/3986201_large.jpg</url>
    <title>
    <en></en>
    </title>
    </image>
    <image id="3986203">
    <url>1204/1204468/3986203_large.jpg</url>
    <title>
    <en></en>
    </title>
    </image>
    <image id="12052352">
    <url>1204/1204468/12052352_large.jpg</url>
    <title>
    <en></en>
    </title>
    </image>
    <image id="3986204">
    <url>1204/1204468/3986204_large.jpg</url>
    <title>
    <en></en>
    </title>
    </image>
    <image id="12052353">
    <url>1204/1204468/12052353_large.jpg</url>
    <title>
    <en></en>
    </title>
    </image>
    </images>
    </property>
    Last edited by cpradio; Apr 15, 2013 at 05:23. Reason: Added XML highlight tags

  2. #2
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,157
    Mentioned
    152 Post(s)
    Tagged
    0 Thread(s)
    xpath?

    PHP Code:
    $xml = new SimpleXMLElement($xmlAsString);
    $images $xml->xpath("/property[descendant::id='1204468']/images"); 

  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)
    I tried this:

    PHP Code:
    $xml simplexml_load_file('file.xml');

    function 
    photos($id$xml) {
        
    $property_id $property->id;
        
    $xml = new SimpleXMLElement($xml);
        
    $photos $xml->xpath("/property[descendant::id='$property_id']/images");  
        return 
    $photos;

    and this

    PHP Code:
    $xml_file 'file.xml';
    function 
    photos($id$xml_file) {
        
    $property_id $property->id;
        
    $xml = new SimpleXMLElement($xml_file);
        
    $photos $xml->xpath("/property[descendant::id='$property_id']/images");  
        return 
    $photos;

    No joy. please help.

  4. #4
    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)
    help please.


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
  •