473,387 Members | 1,532 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Outputting XML via JavaScript

I need to make an HTML page that has multiple choice quiz questions that
pull from an XML doc. I have been looking at various online examples of how
to do this, mainly this one: http://www.quirksmode.org/dom/importxml.html ,
but I can't get this damn thing working. Any help is appreciated, but if you
write out the html/javascript code you'll be my hero.

The example XML doc:

<?xml version="1.0" ?>
<quiz>
<question>
<ask>First question text?</ask>
<choice id="1000">First question first choice</choice>
<choice id="1001">First question second choice</choice>
<choice id="1002">First question third choice</choice>
<choice id="1003">First question fourth choice</choice>
</question>
<question>
<ask>Second question text?</ask>
<choice id="2000">Second question first choice</choice>
<choice id="2001">Second question second choice</choice>
<choice id="2002">Second question third choice</choice>
</question>
<question>
<ask>Third question text?</ask>
<choice id="3000">Third question first choice</choice>
<choiceid="3001"Third question second choice</choice>
<choice id="3002">Third question third choice</choice>
<choice id="3003">Third question fourth choice</choice>
<choice id="3004">Third question fifth choice</choice>
</question>
</quiz>

Should produce something like this:

<div id="quizcontent">
<div id="q1">
<p>Question 1</p>
<p>First question text?</p>
<input name="1000" id="1000" type="radio" value="" /><label
for="1000">First question first choice</label>
<input name="1001" id="1001" type="radio" value="" /><label
for="1001">First question second choice</label>
<input name="1002" id="1002" type="radio" value="" /><label
for="1002">First question third choice</label>
<input name="1003" id="1003" type="radio" value="" /><label
for="1003">First question fourth choice</label>
</div>
<div id="q2">
<p>Question 2</p>
<p>Second question text?</p>
<input name="2000" id="2000" type="radio" value="" /><label
for="1000">Second question first choice</label>
<input name="2001" id="2001" type="radio" value="" /><label
for="1001">Second question second choice</label>
<input name="2002" id="2002" type="radio" value="" /><label
for="1002">Second question third choice</label>
</div>
<div id="q3">
<p>Question 3</p>
<p>Third question text?</p>
<input name="3000" id="3000" type="radio" value="" /><label
for="3000">Third question first choice</label>
<input name="3001" id="3001" type="radio" value="" /><label
for="3001">Third question second choice</label>
<input name="3002" id="3002" type="radio" value="" /><label
for="3002">Third question third choice</label>
<input name="3003" id="3003" type="radio" value="" /><label
for="3003">Third question fourth choice</label>
<input name="3004" id="3004" type="radio" value="" /><label
for="3004">Third question fifth choice</label>
</div>
</div>

Jul 27 '07 #1
5 1486
On Jul 26, 11:50 pm, "Steve" <zarw...@hotmail.comwrote:
I need to make an HTML page that has multiple choice quiz questions that
pull from an XML doc. I have been looking at various online examples of how
to do this, mainly this one:http://www.quirksmode.org/dom/importxml.html,
It is an outdated article, but it does work (in IE7 anyway.)
but I can't get this damn thing working. Any help is
Do you mean you can't get their code working in your browser? Or did
you try to modify it to suit your data? In any event, you need to
provide some more detail about the problem.

Anyway, this processing should be done server-side. Look into XSLT.
If you insist on doing this in the browser, look into AJAX.
Jul 27 '07 #2

"David Mark" <dm***********@gmail.comwrote in message
news:11**********************@j4g2000prf.googlegro ups.com...
On Jul 26, 11:50 pm, "Steve" <zarw...@hotmail.comwrote:
>I need to make an HTML page that has multiple choice quiz questions that
pull from an XML doc. I have been looking at various online examples of
how
to do this, mainly this one:http://www.quirksmode.org/dom/importxml.html,

It is an outdated article, but it does work (in IE7 anyway.)
>but I can't get this damn thing working. Any help is

Do you mean you can't get their code working in your browser? Or did
you try to modify it to suit your data? In any event, you need to
provide some more detail about the problem.

Anyway, this processing should be done server-side. Look into XSLT.
If you insist on doing this in the browser, look into AJAX.

The problem is in the formatting of the data, as is I am able to get it
working in IE6, IE7, Firefox, Safari, etc. I can't do it server-side, has to
be able to run from CD and desktop and Internet connection may or may-not be
available. Don't need AJAX, it can be done onload and doesn't require any
interaction from the user.

Jul 27 '07 #3
On Jul 27, 12:51 am, "Steve" <zarw...@hotmail.comwrote:
[snip]
>
The problem is in the formatting of the data, as is I am able
What is the problem? Post your code.

to get it
working in IE6, IE7, Firefox, Safari, etc.
What is it not working in?
I can't do it server-side, has to
be able to run from CD and desktop and Internet connection may
Okay.

or may-not be
available. Don't need AJAX, it can be done onload and doesn't require any
interaction from the user.
To fetch XML from a remote server, the standard approach is to use an
AJAX request, whether user interaction is involved or not.
Jul 27 '07 #4
rf

"Steve" <za*****@hotmail.comwrote in message
news:_h******************@newsread3.news.pas.earth link.net...
Someone else please, David is being difficult.
You are obviously having problems with your query here. Ask for your money
back :-)

--
Richard.
Jul 27 '07 #5

Steve <za*****@hotmail.comwrote in
<_h******************@newsread3.news.pas.earthlink .net>:
"David Mark" <dm***********@gmail.comwrote in message
>On Jul 27, 1:30 am, "Steve" <zarw...@hotmail.comwrote:
[generating HTML from XML using JavaScript]
>>it's not important. I just need the XML I provided
displayed how I described.

So you want somebody to write it for you from scratch.
[...]
>Anyway, did you try writing the code yourself? If so,
post it and explain what it is doing wrong.

Someone else please, David is being difficult.
Yeah, right. We're falling all over ourselves to do your
bloody job for you. All for a stunning compensation
of 'being your hero'. Do you have a management degree or
something?

--
....the pleasure of obedience is pretty thin compared with
the pleasure of hearing a rotten tomato hit someone in the
rear end. -- Garrison Keillor
Jul 27 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Cynthia | last post by:
Hi all, I have looked through the online manual and haven't found a way to format data from either a form or data that was retrieved from a database. I would like to provide an "elegant" printout...
13
by: Jacek Dziedzic | last post by:
Hello! I have a piece of code that needs to display a formatted table of pointers using streams, with the pointers represented as hex values. It looks more or less like this: #include...
3
by: BakedBean | last post by:
Hi, This is probably really simple, but I've only just been asked to look at this and I've spent a full day trying to get it to work, so any help will be very gratefully received! At present...
2
by: Andy | last post by:
Hi I'm really stuck outputting a double number to the console with three decimal places if the furthest right value is a zero. I can coutput the number 4.546 as 4.546 but then if I output...
2
by: Ed Jay | last post by:
I generate several string in a js. I output the strings to an invisible container using inner.HTML. Then, the container is made visible. For layout purposes, I want to precede some of the strings...
2
by: cephelo | last post by:
I have no problems outputting the attribute value when the node is in context, for example, @id when an <status> node is in context. However, I am having trouble outputting it in a <xsl:value-of...
2
by: andy.z | last post by:
I'm confused - The following outputs a URL encoded string into an alert box ----------------------CUT ---------------------- function createEmbarrasment() { $tmp = urlencode("Your fly is...
4
by: Peter Nimmo | last post by:
Hi, I am writting a windows application that I want to be able to act as if it where a Console application in certain circumstances, such as error logging. Whilst I have nearly got it, it...
1
Markus
by: Markus | last post by:
Little problem here. How would i go about outputting "&raquo;" through giving something a value. i.e. if(validateEmail(emailValue) === false){ emailStyle.color = "red"; emailText.value...
1
by: wbrands2 | last post by:
I am new to this forum and to javascript I have something due for class tomorrow but I can't figure out what is wrong with this code that it won't output a table to the screen. I don't understand how...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.