I have a mysql database that has previously stored the text of an xml file including tags. I want to select that data from the database and return it as an xml file rather than just text, (eg filename.xml). It is to be further processed with a javascript file which will output as HTML. I'm no xml programmer but have been trying a couple of things and have included my most recent attempt below for constructive comment.
The file check.php selects the xml data from the database, but the display does not show any xml tags. They are there though because a view source will show them. I am expecting that if the data is selected and saved into a temporary Result.xml, the header towards the end of check.php will call the javascript file to act on the Result.xml. That's the plan, anyway.
check.php

<?php    
if (isset($_SESSION['id'])) {
include_once("../../real_conn/real_i_conn.php");
    $id   = $_SESSION['id'];
    $userId = $_SESSION['userId'];
    $userIdRec = $id;
    $managerId = $_SESSION['managerId'];
    $userIdRec = $_SESSION['userIdRec'];
    $quizTitle = "";
    $quizTitle = mysqli_real_escape_string($conni, $_GET['quizTitle']);
}
else 
{ 
?>
<html>
<table>
    <td>You must be logged in through the<br />
      <a href="../../index.php">Student Portal</a><br />
      to be able to check your quiz results.</td>
</table>
</html>
<?php
exit;
} 
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html">
<link rel="stylesheet" type="text/css" href="style.css">
<title>Quiz Result Management Panel</title>
</head>
  <?php
    //header("Content-type: text/xml");    
    $sql = "SELECT Result FROM safetyte_stol.quiz WHERE managerId = '$managerId' AND userIdRec = '$userIdRec' AND quizTitle = '$quizTitle'";
        $result = mysqli_query($conni, $sql);
        if (mysqli_num_rows($result) > 0) {
        // output data of each row
             while($row = mysqli_fetch_assoc($result)) {
                 $Result = $row["Result"];
             //$Result=simplexml_load_string($row["Result"]);
             //header("Content-Type: application/xml");
             print_r($Result);
     }
            } else {
             echo "0 results";
     }  

?>
  <table>
    <tr>
      <td>
        <?php echo $userId. ". Here are the results of your most recent ".$quizTitle." Quiz";?><br /></td>
    </tr>
    <tr>
      <td ><?php //header("location: safetytesting.php");?> <br /></td>
    </tr>
        <tr>
          <td>&nbsp;<br />&nbsp;<br /></td> 
        </tr>
      </table>
    </center>
    </div>
    </body>
    </html>

The resultant display produced by the above script begins as follows. I haven't included much of the file because it is too long and generally illelevant, however I suspect the first lines are determining that the file is other than xml.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html">
<link rel="stylesheet" type="text/css" href="style.css">
<title>Quiz Result Management Panel</title>
</head>
<body onBlur="this.focus()" topmargin="18">

<center>
  <quizReport xmlns="http://www.ispringsolutions.com/ispring/quizbuilder/quizresults" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.ispringsolutions.com/ispring/quizbuilder/quizresults quizReport.xsd" version="1"><quizSettings quizType="graded" maxScore="14" maxNormalizedScore="100" timeLimit="0"><passingPercent>1</passingPercent></quizSettings><summary score="12" percent="0.857" time="96"><variables/></summary><questions><trueFalseQuestion id="{5B4DDC46-32A2-4999-A016-FD259B65885B}" status="correct" maxPoints="1" maxAttempts="0" awardedPoints="1" usedAttempts="1"><direction>Choose whether 1+1=2  is true or false.
</direction><answers correctAnswerIndex="0" userAnswerIndex="0"><answer>True
</answer><answer>False
</answer></answers></trueFalseQuestion><trueFalseQuestion id="{9EC057E6-6DFE-44DA-9F94-3A2CA492A82F}" status="correct" maxPoints="1" maxAttempts="0" awardedPoints="1" usedAttempts="1"><direction>Is it dangerous to ride a bicycle.
</direction><answers correctAnswerIndex="1" userAnswerIndex="1"><answer>Yes. Riding a bicycle is one of the most dangerous occupations
</answer><answer>False. Riding a bicycle is a safe exercise.
</answer>

and so on. It is then passed to the following html page for interpretation by javascript. I have no reason to doubt that this will work, but I need to deliver the mysql $Result as an xml file. Any help would be much appreciated.

Hi, I'm not sure I've understood: line 26 of check.php is line 1 of the other code block?

The file check.php selects the xml data from the database, but the display does not show any xml tags.

I'm not sure why you expect to see XML tags on the page. You don't see <h1> or <div> in an HTML either. They're meant to be hidden as they indicate page structure and aren't considered page content.
Do you need to see the XML tags?

Maybe could you be more exact about what you expect to see and what actually happens.

I've narrowed the issue down to the following script.

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<script src='safetytesting.js'></script>
<link rel="stylesheet" type="text/css" href="safetytesting.css">
<script type='text/xml' id='resultData'>'<?php echo $Result; ?>'; 

 </script> 
</head>
<body>
 <div id='report'>Loading your report... If it does not appear, make sure you have Javascript enabled in your browser. </div>
 <script>SafetyTesting.convertResultsToHTML(document.getElementById('resultData'), '../../equipment2/<?php echo $quizTitle; ?>/hotspot images', 'report')</script>
 <div> Echoed php tests follow:..Quiz title is <?php echo $quizTitle; ?> </br> Echoed Result is </br> <?php echo $Result; ?> </div>
</body>
</html>

I have a text variable collected from a database which consists of well formed xml. The variable containing the text is $Results. The seventh line of the above script attempts to insert the php variable $Result into the javascript. It is clearly not working as I have it, but the $Result variable can be echoed correctly at the end of the script. The question is, how can I express the variable $Result so that it can be read by the javascript?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.