Trying to parse xml file for javascript quiz

Posted by App_beginner on Stack Overflow See other posts from Stack Overflow or by App_beginner
Published on 2010-05-22T13:17:48Z Indexed on 2010/05/22 13:20 UTC
Read the original article Hit count: 178

Filed under:
|
|
|
|

Hi

I am trying to create a javascript quiz, that gets the questions from a xml file. At the moment I am only starting out trying to parse my xml file without any success. Can anyone point me to what I am doing wrong?

<html>
<head>
<title>Test</title>
</head>
<body>
<div class="items">
</div>
<script type="text/javascript">
var quizXML = '<quiz><Sporsmal tekst="bla bla bla"/><alternativer><tekst>bla</tekst><tekst>bli</tekst><tekst correct="yes">ble</tekst></alternativer><Sporsmal tekst="More blah"/><alternativer><tekst>bla bla</tekst><tekst correct="yes">bli bli</tekst><tekst>ble ble</tekst></alternativer></quiz>'

var quizDOM = $.xmlDOM( quizXML );

quizDOM.find('quiz > Sporsmal').each(function() {

var sporsmalTekst = $(this).attr('tekst');
var qDiv = $("<div />")
.addClass("item")
.addClass("sporsmal")
.appendTo($(".spmArr"));
var sTekst = $("<h2/>")
.html(sporsmalTekst)
.appendTo(qDiv);
}
</script>
</body>
</html>

When I try this in my browser the classes and div are not being created. And the page is just blank. Am i doing something wrong when I intialize the xml?

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about html