casper
2nd February 2009, 22:38
so i've been assigned to create and manage a page for my school website in our "students interests" area for my web design class. i want to create a interactive table using xml so i can just update a single xml file. and not have to deal with a bunch of tables i've been having problems with it so i figured i would ask on here since some of you guys seem to know some of this stuff(my teacher is useless). i would like the table to just be a javascript file, that way i would just have to load in the xml and javascript and i can display it elsewear, perhaps as a way to show off. I'm new to xml and i've read up on it. hopefully my method i'm trying doesn't seem totally stupid. i would appriciate any help
here is my javascript, it says the errors are that it is expecting a object.
/ JavaScript Document
function loadXMLDoc(dname)
{
try //Internet Explorer
{
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
}
catch(e)
{
try //Firefox, Mozilla, Opera, etc.
{
xmlDoc=document.implementation.createDocument("","",null);
}
catch(e) {alert(e.message)}
}
try
{
xmlDoc.async=false;
xmlDoc.load(dname);
return(xmlDoc);
}
catch(e) {alert(e.message)}
return(null);
}
// load xml doc, requires loadxml function
xmlDoc=loadXMLDoc("xml/EventPage.xml");
//end load
//begin variables
B=0;
a=0;
//end variables
//begin functions
function ForwardSport()
{B+=1};
function BackwardSport()
{B-=1};
function ForwardGame()
{a+=4};
function BackwardGame()
{a-=4};
//end functions
//begin table for buttons
document.write("<table>");
document.write("<tr>");
document.write("<td>");
document.write("<button onclick=\"FowardSport ()\"> Next Sport</button>");
document.write("</td>");
document.write("<td>");
document.write("<button onclick=\"BackwardSport ()\"> Last Sport</button>");
document.write("</td>");
document.write("<td>");
document.write("<button onclick=\"FowardGame ()\"> Next Game</button>");
document.write("</td>");
document.write("<td>");
document.write("<button onclick=\"BackwardGame ()\"> Last Game</button>");
document.write("</td>");
document.write("</tr>");
document.write("</table>");
// end table for buttons
//Title
document.write("<center>");
document.write("<span>");
x=xmlDoc.getElementsByTagName("Sport")[b].childNodes[0];
txt=x.nodeValue;
document.write("txt");
document.write("</span>");
document.write("</center>");
//end title
// begin table for data display
document.write("<table>");
document.write("<th> date </th>");
document.write("<th> Time </th>");
document.write("<th> Where</th>");
document.write("<th> Vrs. </th>");
document.write("<tr>");
document.write("<td>");
x=xmlDoc.getElementsByTagName("Sport")[b].childNodes[a+1];
txt=x.nodeValue;
document.write(txt);
document.write("</td>");
document.write("<td>");
x=xmlDoc.getElementsByTagName("Sport")[b].childNodes[a+2];
txt=x.nodeValue;
document.write(txt);
document.write("</td>");
document.write("<td>");
x=xmlDoc.getElementsByTagName("Sport")[b].childNodes[a+3];
txt=x.nodeValue;
document.write(txt);
document.write("</td>");
document.write("<td>");
x=xmlDoc.getElementsByTagName("Sport")[b].childNodes[a+4];
txt=x.nodeValue;
document.write(txt);
document.write("</td>");
document.write("</tr>");
document.write("</table>");
//end table for data display
and here is my xml document structure:
<?xml version="1.0" encoding="utf-8"?>
<Events>
<Sport type="BasketBall">
<SportName> BasketBall</SportName>
<Date Game="1">
testing
</Date>
<Time Game="1">
testing
</Time>
<Where Game="1">
testing
</Where>
<Vrs Game="1" >
testing
</Vrs>
</Sport>
<Sport type="Soccer">
<SportName> Soccer</SportName>
<Date Game="1">
</Date>
<Time Game="1">
</Time>
<Where Game="1">
</Where>
<Vrs Game="1" >
</Vrs>
</Sport>
<Sport type="footBall">
<SportName>FootBall</SportName>
<Date Game="1">
</Date>
<Time Game="1">
</Time>
<Where>
</Where Game="1">
<Vrs Game="1">
</Vrs>
</Sport>
<Sport type="DramaProductions">
<SportName> DramaProductions</SportName>
<Date Game="1">
</Date Game="1">
<Time Game="1">
</Time>
<Where Game="1">
</Where>
</Sport>
</Events>
here is my javascript, it says the errors are that it is expecting a object.
/ JavaScript Document
function loadXMLDoc(dname)
{
try //Internet Explorer
{
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
}
catch(e)
{
try //Firefox, Mozilla, Opera, etc.
{
xmlDoc=document.implementation.createDocument("","",null);
}
catch(e) {alert(e.message)}
}
try
{
xmlDoc.async=false;
xmlDoc.load(dname);
return(xmlDoc);
}
catch(e) {alert(e.message)}
return(null);
}
// load xml doc, requires loadxml function
xmlDoc=loadXMLDoc("xml/EventPage.xml");
//end load
//begin variables
B=0;
a=0;
//end variables
//begin functions
function ForwardSport()
{B+=1};
function BackwardSport()
{B-=1};
function ForwardGame()
{a+=4};
function BackwardGame()
{a-=4};
//end functions
//begin table for buttons
document.write("<table>");
document.write("<tr>");
document.write("<td>");
document.write("<button onclick=\"FowardSport ()\"> Next Sport</button>");
document.write("</td>");
document.write("<td>");
document.write("<button onclick=\"BackwardSport ()\"> Last Sport</button>");
document.write("</td>");
document.write("<td>");
document.write("<button onclick=\"FowardGame ()\"> Next Game</button>");
document.write("</td>");
document.write("<td>");
document.write("<button onclick=\"BackwardGame ()\"> Last Game</button>");
document.write("</td>");
document.write("</tr>");
document.write("</table>");
// end table for buttons
//Title
document.write("<center>");
document.write("<span>");
x=xmlDoc.getElementsByTagName("Sport")[b].childNodes[0];
txt=x.nodeValue;
document.write("txt");
document.write("</span>");
document.write("</center>");
//end title
// begin table for data display
document.write("<table>");
document.write("<th> date </th>");
document.write("<th> Time </th>");
document.write("<th> Where</th>");
document.write("<th> Vrs. </th>");
document.write("<tr>");
document.write("<td>");
x=xmlDoc.getElementsByTagName("Sport")[b].childNodes[a+1];
txt=x.nodeValue;
document.write(txt);
document.write("</td>");
document.write("<td>");
x=xmlDoc.getElementsByTagName("Sport")[b].childNodes[a+2];
txt=x.nodeValue;
document.write(txt);
document.write("</td>");
document.write("<td>");
x=xmlDoc.getElementsByTagName("Sport")[b].childNodes[a+3];
txt=x.nodeValue;
document.write(txt);
document.write("</td>");
document.write("<td>");
x=xmlDoc.getElementsByTagName("Sport")[b].childNodes[a+4];
txt=x.nodeValue;
document.write(txt);
document.write("</td>");
document.write("</tr>");
document.write("</table>");
//end table for data display
and here is my xml document structure:
<?xml version="1.0" encoding="utf-8"?>
<Events>
<Sport type="BasketBall">
<SportName> BasketBall</SportName>
<Date Game="1">
testing
</Date>
<Time Game="1">
testing
</Time>
<Where Game="1">
testing
</Where>
<Vrs Game="1" >
testing
</Vrs>
</Sport>
<Sport type="Soccer">
<SportName> Soccer</SportName>
<Date Game="1">
</Date>
<Time Game="1">
</Time>
<Where Game="1">
</Where>
<Vrs Game="1" >
</Vrs>
</Sport>
<Sport type="footBall">
<SportName>FootBall</SportName>
<Date Game="1">
</Date>
<Time Game="1">
</Time>
<Where>
</Where Game="1">
<Vrs Game="1">
</Vrs>
</Sport>
<Sport type="DramaProductions">
<SportName> DramaProductions</SportName>
<Date Game="1">
</Date Game="1">
<Time Game="1">
</Time>
<Where Game="1">
</Where>
</Sport>
</Events>