Log in

View Full Version : having problems with xml



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>

apathy maybe
2nd February 2009, 23:38
Meh what?!

I would suggest that you use a sever side language (e.g. PHP) and a database (e.g. MySQL).

Alternativly, just drop the JS, and style the XML file with CSS or something (why XML? why not just HTML?).

You're trying to create a dynamic page with JavaScript? Seems a really silly way to go about it. (Esp. when using document.write(), learn about DOM.)

Yeah dude, the more I look, the more it seems like you would make your life a shit load easier if you just had a fucking HTML table in a proper HTML 4.01 page. Unless you are actually using the data in the XML file for something else (e.g. piping it into a desktop program that has fancy graphics), you don't need to use XML.

If you are worried about updating it... Well, a HTML file is a lot easier to update them an XML file that doesn't even have a proper DTD.

Oh god, I just noticed you are using javascript for the fucking links! DON'T!
Don't ever create functionality in a page with JS that just duplicates functionality already available using (X)HTML and CSS. It pisses of people like me who tend to browse with JS off (NoScript and Firefox, safer surfing, or the crazies who use Lynx), and people who use screen readers etc. that don't like JS.


Some links:
http://validator.w3.org/ make sure you have valid (X)HTML
http://en.wikipedia.org/wiki/Progressive_enhancement
http://www.alistapart.com/articles/understandingprogressiveenhancement (if you are serious about learning web stuff, read A List Apart, it's fucking brilliant!)
Oh, and you can learn more of the web then you ever will in class, well except for design stuff. Design stuff is probably better taught in a class.

casper
3rd February 2009, 00:58
i don't believe our school has php or mysql, and if it did i would have to get special permission in all liklyhood. i wanted it to be javascript that way the table and xml file can be loaded into any page(hence the document.write) i also don't feel like editing the content of the table manually every week. i just want to update a single xml file and allow the user to naviagate through that file so that they can view a few weeks ahead and behind at a click of a button,along with isolating and viewing different sports. hence the BUTTONS(not, links the onclick equals a function call and are supposed to effect my xml DOM attempts (which is what i'm having problems with))

i am styling the page with css. i believe i'm going to go with a dark blue and white color scheme.

apathy maybe
3rd February 2009, 13:10
Well, it's your hassle. I can't help you with what you have (JS is not a strong point of mine).

But seriously, updating a HTML table is no more hassle than updating an XML file.

Also, try on a proper web stuff forum. Most folks on RevLeft know fuck all about web stuff. Those who do, like me, I believe, are all amateurs anyway.

casper
3rd February 2009, 19:22
ok, thanks for looking at it. i decided to register at the w3 forums. i'm probally going to have more questions. i was just being lazy and didn't feel like registering at another forum or searching for the response a day later in one that allowed guests to post threads.