Jump to content

Some Trouble Displaying Xml Elements


chibineku

Recommended Posts

Hiya. I'm new to JavaScript and XML, but I have been cannabalizing and adapting code for about a week and I have a general idea of how things work. However, I'm having some trouble making a simple XML call and display script working. Here is a link:http://www.sinaesthesia.co.uk/divlayout3It's a scruffy practice site, so forgive the layout, colours, etc. etc.I am attempting to make the menu a series of onclicks that call functions in the header, which in turn call and display CONTENT elements from various XML files. I am pretty lost and won't even hazard guesses why it doesn't work, but any help or tips at all would be great.It will probably wind up being easier creating new pages for each of the menu items, as is traditional, but I like the sleekness of javascripts because the page doesn't have to reload. It's quick and it looks smooth. However, I'd rather be sane than smooth.Thanks in advance for any help,Jonathon

Link to comment
Share on other sites

The first problem I find is this:

welcome=(x[0].getElementsByTagName("CONTENT")[0].childNodes[0].nodeValue);

Looking at your code, I'd say it has to be like this:

welcome=(x.documentElement.getElementsByTagName("CONTENT")[0].childNodes[0].nodeValue);

Link to comment
Share on other sites

That may be the first, but it sure isn't the last. I have changed the line to the one you suggested but it had no effect. If it helps, the XML file is:<?xml version="1.0" encoding="utf-8"?><WELCOME><CONTENT>Chocolate is the most recent offering from visionary martial arts director Prachya Pinkaew and, like the two before it (Tom Yum Goong aka The Warrior King, and Ong Bak, which turned Tony Jaa into a household name - well, in households that have at least one Bruce Lee movie, anyway), it is, in a word, awesome. In a few more words, it's also breath-taking, stunning, painful, funny... I could go on, and I will, otherwise this wouldn't be much of a movie review, but I'll do it in fuller, more rounded sentences. Starring newcomer JeeJa Yanin, Chocolate tells the story of Zen, the autistic daughter of a cancer-stricken ex-gangster as she tries to pay for her mother's hospital bills. Aided and abetted by her friend Moom, she sets out to collect on some unpaid debts from a variety of unsavoury characters who, unperturbed by her youth, mental handicap and plight, attempt to beat the ###### out of her and Moom. What they haven't counted on, however, is that Zen is an autistic savant whose particular area of expertise is...beating the ###### out of people.</CONTENT><IMG></IMG></WELCOME>The blurb is just a placeholder and so I know if something is happening. The frustrating thing is that the javascript for the table on the right hand side of the page displays text in the maindiv in almost exactly the same manner, yet it doesn't work here.

Link to comment
Share on other sites

Looking at it closer, you've defined x outside of the function, so it doesn't contain the nodes of the xmlDoc file because the file was created after.Try this:

function welcome(){	xmlDoc.async=false;xmlDoc.load("welcome.xml");welcome=(xmlDoc.getElementsByTagName("CONTENT")[0].childNodes[0].nodeValue);document.getElementById("content").innerHTML="<p class='wrap'>"+welcome+"</p>"}

Link to comment
Share on other sites

Ahh! You are a genius! Or, I am dumb enough that you seem like one. Either way, I would kiss you were you more proximal.Many thanks, once again. Warning: don't celebrate just yet, you haven't heard the last from chibin00bu...

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...