M
MaryA
Let me preface this with the fact that I am a newbie to HTML, XML and
Javascript. Having said that, let me explain my dilemma:
I am having a difficult time getting innerHTML to consistently return
the entire HTML string when a <p> is part of the text. It somehow
throws everything off. I am trying to store exam questions in an
Oracle Database as XML.
The XML I started with looked like this:
<aicpcu id="XMLTEXT"><stem id="STEM">This is my stem<p>this is the
second line</p></stem><options id="OPTIONS"><distracter
id="DISTRACTER">distracter 1</distracter>"><distracter
id="DISTRACTER">distracter 2</distracter>"><distracter
id="DISTRACTER">distracter 3</distracter>"><distracter
id="DISTRACTER">distracter 4</distracter></options></aicpcu>
I used this code to get at the text I wanted for the stem:
var s = document.getElementById("STEM");
alert(s.innerHTML);
I would only get This is my stem.
However, when I changed the XML to:
<div id="STEM" mix="Y">This is my stem<p><b>This is the second
line.</b></p></div>
I would get both lines.
Now for the distracter part. Since I got the stem working properly, I
tried to modify what I had in a similar manner. I've tried many
iterations of this, but this gives me the closest to what I want;
<div id="DISTRACTERS"><distracter id="DISTRACTER" label="A">First
distracter</distracter><distracter id="DISTRACTER" label="B"><b>Second
distracter</b></distracter><distracter id="DISTRACTER"
label="C"><i>Third distracter</i></distracter><distracter
id="DISTRACTER" label="D">Fourth distracter<p>second
sentence</p></distracter></div>
The code I use to extract the innerHTML is:
var d = document.getElementById("DISTRACTERS");
alert(d.childNodes.length); -- returns 5 (the <p> apparently shows as a
separate child)
var dList = document.getElementsByTagName("DISTRACTER");
alert(dList.length); -- returns 4 (correct)
for (var j=0; dList.length > j; j++)
{
htp.p(' alert(dList[j].innerHTML);');
}
All the innerHTML is displayed properly except the 4th one that has 2
paragraphs to it. I just get the text "Fourth distracter".
Any help would be greatly appreciated.
Javascript. Having said that, let me explain my dilemma:
I am having a difficult time getting innerHTML to consistently return
the entire HTML string when a <p> is part of the text. It somehow
throws everything off. I am trying to store exam questions in an
Oracle Database as XML.
The XML I started with looked like this:
<aicpcu id="XMLTEXT"><stem id="STEM">This is my stem<p>this is the
second line</p></stem><options id="OPTIONS"><distracter
id="DISTRACTER">distracter 1</distracter>"><distracter
id="DISTRACTER">distracter 2</distracter>"><distracter
id="DISTRACTER">distracter 3</distracter>"><distracter
id="DISTRACTER">distracter 4</distracter></options></aicpcu>
I used this code to get at the text I wanted for the stem:
var s = document.getElementById("STEM");
alert(s.innerHTML);
I would only get This is my stem.
However, when I changed the XML to:
<div id="STEM" mix="Y">This is my stem<p><b>This is the second
line.</b></p></div>
I would get both lines.
Now for the distracter part. Since I got the stem working properly, I
tried to modify what I had in a similar manner. I've tried many
iterations of this, but this gives me the closest to what I want;
<div id="DISTRACTERS"><distracter id="DISTRACTER" label="A">First
distracter</distracter><distracter id="DISTRACTER" label="B"><b>Second
distracter</b></distracter><distracter id="DISTRACTER"
label="C"><i>Third distracter</i></distracter><distracter
id="DISTRACTER" label="D">Fourth distracter<p>second
sentence</p></distracter></div>
The code I use to extract the innerHTML is:
var d = document.getElementById("DISTRACTERS");
alert(d.childNodes.length); -- returns 5 (the <p> apparently shows as a
separate child)
var dList = document.getElementsByTagName("DISTRACTER");
alert(dList.length); -- returns 4 (correct)
for (var j=0; dList.length > j; j++)
{
htp.p(' alert(dList[j].innerHTML);');
}
All the innerHTML is displayed properly except the 4th one that has 2
paragraphs to it. I just get the text "Fourth distracter".
Any help would be greatly appreciated.