0

`

<Listings>
    <Listing last_update="2017-11-15 06:01:02">
        <count>1</count>
        <Property_Ref_No>CO-S-1147</Property_Ref_No>
        <Ad_Type>Sale</Ad_Type>
        <Unit_Type>Office</Unit_Type>
        <Tenanted>0</Tenanted>
        <Furnished>2</Furnished>
        <Unit_Model/>
        <Images>
            <image>image 1</image>
            <image>image 2</image>
            <image>image 3</image>
        </Images>
    </listing>
</Listings>

`

i have used php while loop

$i=0;
        while(is_object($finance = $doc->getElementsByTagName("Images")->item($i)))
        {

                 foreach($finance->childNodes as $nodename)
                 {
                         if($nodename->nodeName=='image')
                            {
                                 foreach($nodename->childNodes as $subNodes)
                                 {
                                 echo $subNodes->nodeName." - ".$subNodes->nodeValue."<br><br><br>";
                                 }
                            }
                         else
                            {
                            echo $nodename->nodeName." - ".$nodename->nodeValue."<br>";
                            }
                 }
  $i++;
        }

this loop gives me the child node value but i also need parent nodes value as well

I want this xml data in php to and show all the parent and child data using loop need help on this please .

thank you.

  • what have you tried so far? also i suggest to read this post https://stackoverflow.com/questions/1397036/how-to-convert-array-to-simplexml – Bilal Ahmed Jan 17 '18 at 07:22
  • You can find or get answer of your question here - [link](https://stackoverflow.com/questions/6578832/how-to-convert-xml-into-array-in-php) – Gur Janjua Jan 17 '18 at 07:24
  • have used while loop of php to get the child node i.e image tag value. but i also want the other tag values as well that are outside child nodes. – Neetesh Singh Jan 17 '18 at 07:41
  • Well then don’t loop over the children of the Images elements, but over those of Listing …? – CBroe Jan 17 '18 at 08:21

0 Answers0