0
<Pages TotalPages="56" ProductCode="Headline" PubDate="2012-01-31" PubVersion="0" PubSubVersion="0" PageWidth="1622" PageHeight="1902">
              <Page PageNo="1" PageName="" PageType="" Section="Section" ThumbnailPath="http://203.80.1.28/FlippingBook/Dev/Frontend/demo/Headline/2012/12/20/0/0/A/Content/1/Pv001.png" ImagePath="http://203.80.1.28/FlippingBook/Dev/Frontend/demo/Headline/2012/12/20/0/0/A/Content/1/Pg001_142_p.jpg" OverlayFullPath="http://203.80.1.28/FlippingBook/Dev/Frontend/demo/Headline/2012/12/20/0/0/A/Content/1/Pg001_142_t.png" PreviewPath="http://203.80.1.28/FlippingBook/Dev/Frontend/demo/Headline/2012/12/20/0/0/A/Content/1/Pg001.png" IsPreview="true" ImageHeight="1902" ImageWidth="1622" WithResource="true" /> 
              <Page PageNo="2" PageName="" PageType="" Section="Section" ThumbnailPath="http://203.80.1.28/FlippingBook/Dev/Frontend/demo/Headline/2012/12/20/0/0/A/Content/2/Pv002.png" ImagePath="http://203.80.1.28/FlippingBook/Dev/Frontend/demo/Headline/2012/12/20/0/0/A/Content/2/Pg002_142_p.jpg" OverlayFullPath="http://203.80.1.28/FlippingBook/Dev/Frontend/demo/Headline/2012/12/20/0/0/A/Content/2/Pg002_142_t.png" PreviewPath="http://203.80.1.28/FlippingBook/Dev/Frontend/demo/Headline/2012/12/20/0/0/A/Content/2/Pg002.png" IsPreview="true" ImageHeight="1902" ImageWidth="1622" WithResource="true" /> 
</Pages>

PHP:

$xml = simplexml_load_file($dir) 
       or die("Error: Cannot create object");
//$fileList = array();

foreach($xml->children() as $Pages){
    foreach($Pages->children() as $Page => $page){
    $fileLink = $page['ThumbnailPath'];
    echo $fileLink;
    }
}

What I am going to get is the ThumbnailPath from node "Page" , I loop through Pages and page but it turn out gets nothing, how to fix this problem ? Thanks

4
  • Can you show me what is $dir ? Commented Jan 25, 2013 at 8:49
  • sure, $dir is the path of xml file , and it is exist Commented Jan 25, 2013 at 8:50
  • the xml ($dir) is shown above Commented Jan 25, 2013 at 8:54
  • 1
    please var_dump($xml->children()) and paste to your question. Commented Jan 25, 2013 at 8:57

3 Answers 3

1

It's easy to fix

$xml = simplexml_load_file("test.xml")
       or die("Error: Cannot create object");
//$fileList = array();


foreach($xml->children() as $Pages){
    print_r($Pages['ThumbnailPath']);
}
Sign up to request clarification or add additional context in comments.

Comments

1

You don't have to loop over "Pages" as it already is the xml root element. So you can just omit the second loop:

 $xml = simplexml_load_string($string) or die("Error: Cannot create object");
 //$fileList = array();

foreach($xml->children() as $Page){
    $fileLink = $Page['ThumbnailPath'];
    echo $fileLink;
}

Comments

1

Try this:

foreach($xml->children() as $Pages){
    echo $Pages['ThumbnailPath'][0].'<br>';
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.