XML textnode issues

I am building a small FAQ for work and wanted to learn how to use XML at the same time. I can load the XML file no problem… just the parsing and displaying seems to be giving me grief…

I’ve posted on some other excellent forums but have yet to find an answer… hopefully somebody here will be able to send me in the right direction…

my xml file is simple :

[AS]<questions>
<q1>question1</q1>
<q2>question2</q2>
<q3>question3</q3>
<q4>question4</q4>
<q5>question5</q5>
<q6>question6</q6>
<q7>question7</q7>
<q8>question8</q8>
<q9>question9</q9>
<q10>question10</q10>
</questions>
[/AS]

I want people to be able to select the question and have the answer pop up in a dynamic text box… I’ve found some similar little projects but the xml file was generated using php… which for me is not an option since I would be updating the xml file using Notepad… I would use arrays in Flash… but my workplace doesn’t have the license for it… so I figure XML is dynamic… and its also a good opportunity to get familiar with it… so… here is my function :

[AS]function getQuestions(xml_doc) {
var faqQuestions = xml_doc.firstChild.childNodes;
var totalQuestions = faqQuestions.length;
var myAnswer = myBox.getSelectedItem();
theAnswer = myAnswer.data;
for (i=0; i<totalQuestions; i++) {
myBox.addItem(faqQuestions*, answers*);
}
}[/AS]

This displays my xml file allright… but with the q1, q2, q3 tags as well… I was told this is happening because I am using textnodes… so… Is there a way I can recurse this function so as to only get the questions to display in the listbox UI component?

I managed to get just the first one in there by changing

[AS]var faqQuestions = xml_doc.firstChild.childNodes;[/AS]

to

[AS]var faqQuestions = xml_doc.firstChild.firstChild.childNodes;[/AS]

But of course… I need more than one question to display…

Any help is greatly appreciated.

Example:

[AS]myXML = new XML();
myXML.ignoreWhite = true;
myXML.onLoad = function(success) {
if (success) {
totalQuestions = this.firstChild.childNodes.length;
for (i=0; i<totalQuestions; i++) {
trace(this.firstChild.childNodes*.firstChild);
}
} else {
trace(“error loading xml file”);
}
};
myXML.load(“xml_doc.xml”);[/AS]

Does that example help any?

Lostinbeta, you rule!

Hehehe… I knew it was something simple… your trace fixed the problem beautifully!

This is the function that now works :

[AS]function getQuestions(xml_doc) {
var faqQuestions = xml_doc.firstChild.childNodes;
var totalQuestions = faqQuestions.length;
var myAnswer = myBox.getSelectedItem();
theAnswer = myAnswer.data;
for (i=0; i<totalQuestions; i++) {
myBox.addItem(faqQuestions*.firstChild, answers*);
}
}[/AS]

Thanks!! I just have a few more things to figure out so I might be posting again but that did the trick for this problem.

I am glad I could help :slight_smile: