Hello Everyone,
Nogdog the script worked great and that data has been taken care of. I do have one more file that I need to insert that is a little more complicated, but I think can use the same principle. I need to load the data into variables that I can work with. I have one area that is giving me a problem and I wanted to see if anybody can help. Here is my new xml data breakdown that I am working with.
<topics>
<item id="1" answer_id="B">
<question><![CDATA[This is where the Main data is located]]></question>
<replies>
<reply id="A"><![CDATA[Answer Option A]]> </reply>
<reply id="B"><![CDATA[Answer Option B]]>
<description><![CDATA[Explination of question]]></description>
</reply>
<reply id="C"><![CDATA[Answer Option C]]></reply>
<reply id="D"><![CDATA[Answer Option D]]></reply>
</replies>
</item>
</topics>
I can get all of the data loaded into variable except for all four of the <reply>'s. I can find the first one, but not the following three others. Can anybody let me know what I am doing wrong. How should I be calling the data for these <reply> items?
Here is the php code I am working with.
<?php
error_reporting(E_ALL);
include 'xmlFile.php';
$xml = new SimpleXMLElement($xmlstr);
$text = $xmlstr;
$xml = simplexml_load_string($text, 'SimpleXMLElement', LIBXML_NOCDATA);
foreach($xml->item as $item) {
foreach ($item->question as $question) {
foreach ($item->replies as $replyGroup) {
foreach ($replyGroup->reply as $replyMain) { // This gives me the first reply but not the rest
foreach ($replyMain->description as $desc) {
}
}
}
}
echo "Situation : ".$question."<br>Correct Reponse: ".$replyMain['id']."<br>Why: ".$desc."<br>Reply One: ".$replyMain."<br>Reply Two: <br>Reply Three: <br>Reply Four: <br><br>";
}
?>
Thanks in advance