0

Hello,

Basically, I am trying to loop though an OPF document which is an XML document to link 2 children of different nodes together. If I do not use an if statement in the second for each loop, I can display all children from <manifest>, however I need the if statement becuase I only want to display the children which match there id attribute with the previously gotten idref attribute which I have stored and I know is not empty and is definitley the same as the id, so I do not understand why this is not working as I have tested and tested...

Here's my PHP:

<?php
$xml = simplexml_load_file("content.opf");

$items = "";

echo "<strong>IDRefs:</strong><br /><br />";
foreach ($xml->spine->children() as $idref) {
    $itemref1 = $idref['idref'];
    echo $itemref1."<br />";
    echo "<br /><strong>Items:</strong><br /><br />";
    foreach ($xml->manifest->children() as $item) {
        if($idref['idref'] == $item['id']) {
            $items .= $item['href'].",";
            echo $item['id'].":".$item['href']."<br />";
        }
    }
    echo "<hr />";
}

echo "<br /><br />";

$title = $xml->metadata->children('dc', true)->title;
$creator = $xml->metadata->children('dc', true)->creator;
$description = $xml->metadata->children('dc', true)->description;
$publisher = $xml->metadata->children('dc', true)->publisher;
$date = $xml->metadata->children('dc', true)->date;
$rights = $xml->metadata->children('dc', true)->rights;
$language = $xml->metadata->children('dc', true)->language;

die($items."<br /><br />".$title."<br />".$creator."<br />".$description."<br />".$publisher."<br />".$date."<br />".$rights."<br />".$language);
?> 

Here is the XML I am working with:

<?xml version="1.0" encoding="UTF-8"?>
<package xmlns="http://www.idpf.org/2007/opf" xmlns:dc="http://purl.org/dc/elements/1.1/"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         version="2.0"
         unique-identifier="bookid">
   <metadata xmlns:dc="http://purl.org/dc/elements/1.1/"  xmlns:opf="http://www.idpf.org/2007/opf">
      <dc:creator>Brooke, Leslie</dc:creator>
      <dc:title>Little Bo-Peep: A Nursery Rhyme Picture Book</dc:title>
      <dc:language xsi:type="dcterms:RFC3066">en-GB</dc:language>
      <dc:rights>Public Domain</dc:rights>
      <dc:publisher>Project Gutenberg (epub version: Bob DuCharme)</dc:publisher>
      <dc:identifier id="bookid">http://www.snee.com/epub/pg23598</dc:identifier>
   </metadata>
   <manifest xmlns:opf="http://www.idpf.org/2007/opf">
      <item id="ncx" href="toc.ncx" media-type="text/xml"/>
      <item id="main" href="23598-h.htm" media-type="application/xhtml+xml"/>
      <item id="imgcover" href="images/imgcover.jpg" media-type="image/jpeg"/>
      <item id="img2" href="images/img2.jpg" media-type="image/jpeg"/>
      <item id="img4" href="images/img4.jpg" media-type="image/jpeg"/>
      <item id="img5" href="images/img5.jpg" media-type="image/jpeg"/>
      <item id="img6" href="images/img6.jpg" media-type="image/jpeg"/>
      <item id="img8" href="images/img8.jpg" media-type="image/jpeg"/>
      <item id="img9" href="images/img9.jpg" media-type="image/jpeg"/>
      <item id="img10" href="images/img10.jpg" media-type="image/jpeg"/>
      <item id="img11" href="images/img11.jpg" media-type="image/jpeg"/>
      <item id="img13" href="images/img13.jpg" media-type="image/jpeg"/>
      <item id="img14" href="images/img14.jpg" media-type="image/jpeg"/>
      <item id="img16" href="images/img16.jpg" media-type="image/jpeg"/>
      <item id="img17" href="images/img17.jpg" media-type="image/jpeg"/>
      <item id="img19" href="images/img19.jpg" media-type="image/jpeg"/>
      <item id="img20" href="images/img20.jpg" media-type="image/jpeg"/>
      <item id="img22" href="images/img22.jpg" media-type="image/jpeg"/>
      <item id="img23" href="images/img23.jpg" media-type="image/jpeg"/>
      <item id="img24" href="images/img24.jpg" media-type="image/jpeg"/>
      <item id="img25" href="images/img25.jpg" media-type="image/jpeg"/>
      <item id="img27" href="images/img27.jpg" media-type="image/jpeg"/>
      <item id="img28" href="images/img28.jpg" media-type="image/jpeg"/>
      <item id="img29" href="images/img29.jpg" media-type="image/jpeg"/>
      <item id="img31" href="images/img31.jpg" media-type="image/jpeg"/>
      <item id="img32" href="images/img32.jpg" media-type="image/jpeg"/>
   </manifest>
   <spine toc="ncx">
      <itemref idref="main"/>
   </spine>
</package>

It displays the title, creator, etc fine, it's just that one if statment in the second for each that is not working right:

if($idref['idref'] == $item['id']) {

Thanks for you time, any help will be greatly appreciated!

1
Contributor
1
Reply
3
Views
5 Years
Discussion Span
Last Post by BlueCharge
0

Maybe I explained terribly, which I tend to do, I apologise, basically all this code works except the if statement, do could someone take a look at the if statement for me, thank you :)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.