- Home /
Question by
SergiuWD · Jun 12, 2015 at 02:31 PM ·
arrayxmlmultidimensional array
How can I turn XML to array?
I have this XML:
<?xml version="1.0" encoding="UTF-8" ?>
<Questions>
<Question QuestionText="A question?" Answer1="Nothing" Answer2="Yes" Answer3="No" Answer4="Maybe" CorrectAnswer="2"/>
<Question QuestionText="What you gonna do?" Answer1="Nothing" Answer2="Idk" Answer3="Something" Answer4="Anything" CorrectAnswer="3"/>
</Questions>
And I am trying to get the questions into an array. Basically I am trying to create a multidimensional array Questions
that contains arrays with this structure:
question[question] = "Question text"
question[answer1] = "Answer 1"
question[answer2] = "Answer 2"
question[answer3] = "Answer 3"
question[answer4] = "Answer 4"
question[correct] = "Correct answer"
I have managed to create a while
function that stores the values into variables. How can I do this?
Here is my code that stores the values into variables:
void Awake()
{
if (QuestionsXml != null)
{
XmlTextReader reader = new XmlTextReader(new StringReader(QuestionsXml.text));
while (reader.Read())
{
if (reader.Name == "Question")
{
question = reader.GetAttribute("QuestionText");
answer1 = reader.GetAttribute("Answer1");
answer2 = reader.GetAttribute("Answer2");
answer3 = reader.GetAttribute("Answer3");
answer4 = reader.GetAttribute("Answer4");
correct = reader.GetAttribute("CorrectAnswer");
}
}
}
}
Comment
Your answer
Follow this Question
Related Questions
Trying to Sort a Multi Dimensional Array 1 Answer
How to Create Multidimensional Array in Javascript? 1 Answer
Parsing XML - appropriate array size 3 Answers
Are multidimensional arrays supported in UNET? 1 Answer
Array of arrays of Textures 2 Answers