How Load XML File in java?

Hi…

I have this XML File:

<?xml version="1.0" encoding="utf-8" ?>
<Question Text="What is the common name for ascorbic acid ?">
	<Answer Text="Vitamin C" Correct="True"></Answer>
	<Answer Text="Vitamin A" Correct="False"></Answer>
	<Answer Text="Vitamin B" Correct="False"></Answer>
	<Answer Text="Vitamin D" Correct="False"></Answer>
</Question>

it’s contain a 2 question and 4 answers for every one , how can I load the first question and the answers ??

please JAVA Code
How can I Load from XML File

Unity does not use Java.

2 Answers

2

This might help you out: unifycommunity.com

I have to use this script to read xml in unity! And it is Unity JavaScript!

var XMLFile : TextAsset;

function Start ()
{
    if(XMLFile != null)
    {
        var reader:XmlTextReader = new XmlTextReader(new StringReader(XMLFile.text));
        while(reader.Read())
        {
            if(reader.Name == "Answer")
            {		
                Debug.Log(reader.Name + "Text = " + reader.GetAttribute("Text") + "  " + "Correct = " + reader.GetAttribute("Correct"));
            } 
        } 
    }
}

thank a lot

This is great! All that I have found on loading xml this way was using c#. As you might have noticed there are a few more hoops to jump through to use js. Thank you!