-1

I have this xml, and I cannot find a way to read all of this data with PHP. I have tried the simple:

$xmlDoc->load("data/xml/page.xml");

with all the rest, but in a way or in another, I cannot find a way to read the name of the gallery (in this xml) and the url/attribute of the image

<DOCUMENT>  <galleries_group>
<GROUP id="main_gallery_group">
  <DATA id="category_name">
    <CONTENT><![CDATA[Black & White]]></CONTENT>
  </DATA>
  <GROUP id="sub_gallery_group">
    <DATA id="gallery_name">
      <CONTENT><![CDATA[WOMENS]]></CONTENT>
    </DATA>
    <GROUP id="sub_gallery_image">
      <DATA id="gallery_thumb">
        <CONTENT>
          <SRC width="277" height="366">images/black_white/005_th.jpg</SRC>
        </CONTENT>
      </DATA>
      <DATA id="gallery_image">
        <CONTENT>
          <SRC width="817" height="1080">images/black_white/005.jpg</SRC>
        </CONTENT> </DATA>
    </GROUP>
    <GROUP id="sub_gallery_image">
      <DATA id="gallery_thumb">
        <CONTENT>
          <SRC width="515" height="366">images/black_white/006_th.jpg</SRC>
        </CONTENT>
      </DATA>
      <DATA id="gallery_image">
        <CONTENT>
          <SRC width="1521" height="1080">images/black_white/006.jpg</SRC>
        </CONTENT>
      </DATA>
    </GROUP>
  </GROUP><GROUP id="main_gallery_group">
  <DATA id="category_name">
    <CONTENT><![CDATA[Gallery ..n]]></CONTENT>
  </DATA>
  <GROUP id="sub_gallery_group">
    <DATA id="gallery_name">
      <CONTENT><![CDATA[GROUP 1]]></CONTENT>
    </DATA>
    <GROUP id="sub_gallery_image">
      <DATA id="gallery_thumb">
        <CONTENT>
          <SRC width="484" height="366">images/gallery/01_th.jpg</SRC>
        </CONTENT>
      </DATA>
      <DATA id="gallery_image">
        <CONTENT>
          <SRC width="1429" height="1080">images/gallery/01.jpg</SRC>
        </CONTENT>
      </DATA>
    </GROUP> 
    <GROUP id="sub_gallery_image">
      <DATA id="gallery_thumb">
        <CONTENT>
          <SRC width="399" height="366">images/gallery/02_th.jpg</SRC>
        </CONTENT>
      </DATA>
      <DATA id="gallery_image">
        <CONTENT>
          <SRC width="981" height="900">images/gallery/02.jpg</SRC>
        </CONTENT>
      </DATA>
    </GROUP>
    </GROUP>
  <GROUP id="sub_gallery_group">
    <DATA id="gallery_name">
      <CONTENT><![CDATA[GROUP N]]></CONTENT>
    </DATA><GROUP id="sub_gallery_image">
      <DATA id="gallery_thumb">
        <CONTENT>
          <SRC width="483" height="366">images/gallery/09_th.jpg</SRC>
        </CONTENT>
      </DATA>
      <DATA id="gallery_image">
        <CONTENT>
          <SRC width="1065" height="600">images/gallery/09.jpg</SRC>
        </CONTENT>
      </DATA>
    </GROUP>
    <GROUP id="sub_gallery_image">
      <DATA id="gallery_thumb">
        <CONTENT>
          <SRC width="235" height="366">images/gallery/10_th.jpg</SRC>
        </CONTENT>
      </DATA>
      <DATA id="gallery_image">
        <CONTENT>
          <SRC width="1920" height="1080">images/gallery/10.jpg</SRC>
        </CONTENT>
      </DATA>
    </GROUP>
   </GROUP> 
  </GROUP>     
</GROUP>   <GROUP id="text_pages_group">
<GROUP id="text_page_group">
  <DATA id="text_page_name">
    <CONTENT><![CDATA[About]]></CONTENT>
  </DATA>
  <DATA id="text_page_text">
    <CONTENT><![CDATA[text12]]></CONTENT>
  </DATA>
</GROUP></GROUP><GROUP id="text_pages_group"><GROUP id="text_page_group">
  <DATA id="text_page_name">
    <CONTENT><![CDATA[Contact]]></CONTENT>
  </DATA>
  <DATA id="text_page_text">
    <CONTENT><![CDATA[text22]]></CONTENT>
  </DATA>
</GROUP></GROUP></DOCUMENT>

of course this is a small xml (just for example) but the complete one have the same format type, any help ?

icodebuster
  • 8,890
  • 7
  • 62
  • 65

1 Answers1

0

You might want to try something like this and adjust the XPath to your needs.

<?php
$xmlDoc = simplexml_load_file('data/xml/page.xml');
$result = $xmlDoc->xpath('/DOCUMENT//GROUP/DATA/CONTENT');
while (list(, $node) = each($result)) {
    echo $node;
}
?>

Watch out though, because the XML you originally posted is not wellformed. <galleries_group> in line 1 is either not closed properly or completely dispensable.

hielsnoppe
  • 2,819
  • 3
  • 31
  • 56