PDA

View Full Version : Retrieve select data from multiple entries in an XML file



PC Rider
11-15-2011, 08:58 PM
I want to make a page that selects distinct values for one person from an XML file into a table. The XML has multiple entry's for this person. I can get all of the data, or just the first one, but I want all data of one person, represented by his or hers "INLOGKODE".

Here's the basic XML structure:

<?xml version="1.0" encoding="UTF-8"?>
<dataroot xmlns:od="urn:schemas-microsoft-com:officedata" generated="2011-11-06T20:46:01">
<History>
<INLOGKODE>Beer4</INLOGKODE>
<DATUM>2011-04-18T00:00:00</DATUM>
<SCORE>38</SCORE>
<HCP-OUD>21.5</HCP-OUD>
<HCP-NIEUW>20.7</HCP-NIEUW>
<OPMERKING>Damesmiddag</OPMERKING>
</History>
</dataroot>

I attached a shortened version of the file, renamed it to History.txt due to extension restrictions for attachments.

I have the following Javascript, it is a nested loop:




<?php session_start();
$_SESSION["user_login"] = $DataArray[2];
$_SESSION["display_name"] = $DataArray[3];
require_once( '../../../../wp-load.php' );
global $current_user;
get_currentuserinfo();

echo 'Welkom '.$current_user->display_name . '. Uw inlogkode is: '.$current_user->user_login. "\n";
?>

<script type="text/javascript">
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET","History.xml",false);
xmlhttp.send();
xmlDoc=xmlhttp.responseXML;

document.write("<table border='1'>");
var x=xmlDoc.getElementsByTagName("History");
var persoon = "<?php echo $current_user->user_login ?>";
var inlogkode = xmlDoc.getElementsByTagName("INLOGKODE")[0].childNodes[0].nodeValue;
for (i = 1; i < inlogkode.length; i++)
{
inlogkode =(x[i].getElementsByTagName("INLOGKODE")[0].childNodes[0].nodeValue);

if ( inlogkode == persoon ) //The condition for another loop

{

for (j = 0; j < inlogkode.length; j++)

document.write("<tr><td>");
document.write(x[j].getElementsByTagName("DATUM")[0].childNodes[0].nodeValue);
document.write("</td><td>");
document.write(x[j].getElementsByTagName("SCORE")[0].childNodes[0].nodeValue);
document.write("</td><td>");
document.write(x[j].getElementsByTagName("HCP-OUD")[0].childNodes[0].nodeValue);
document.write("</td><td>");
document.write(x[j].getElementsByTagName("HCP-NIEUW")[0].childNodes[0].nodeValue);
document.write("</td><td>");
document.write(x[j].getElementsByTagName("OPMERKING")[0].childNodes[0].nodeValue);
document.write("</td></tr>");

}
else // If not, continue the first loop. incrementi by one
{
(i=i+1)
}

}


{
document.write (inlogkode)
document.write (persoon)
}

document.write("</table>");
</script>


I can see that the file gets loaded and that variables are set, but the code does not give a table.

What's wrong? I am stuck right now....

P.S. Funny to see the embarrased smileys for MS, I did notput them in!