hello everyone,
I’ve been having a lot of difficulty in getting this to work. I’ve scoured the internet for a solution, but couldn’t find any.
Here is my problem:
This is the XML document that I need to append to.
<?xml version="1.0" encoding="utf-8"?>
<Participants>
<Participant>
<Price>175000</Price>
<Choice>Neither</Choice>
<Choice>1</Choice>
<Choice>Neither</Choice>
<Municipality>NDG</Municipality>
<HouseholdSize>4</HouseholdSize>
<Gender>Female</Gender>
<Age>55-64</Age>
<Employment>student and employed</Employment>
<Income>75000-99999</Income>
</Participant>
<Participant>
<Price>225000</Price>
</Participant>
</Participants>
I need to append to the second Participant and I have the following code to do so.
if(File.Exists("Information.xml") && PlayerPrefs.GetInt("Participant size")>1)
{
var tracker=PlayerPrefs.GetInt("Participant size");
xmlRead.WhitespaceHandling=WhitespaceHandling.None;
xmlRead.MoveToContent();
xmlRead.Read();
for(var i=1;i<tracker;i++)
{
xmlRead.Skip();
xmlRead.Skip();
}
doc.Load(xmlRead);
var elem =doc.CreateElement("Choice");
elem.InnerText=Choice();
doc.DocumentElement.AppendChild(elem);
xmlRead.Close();
doc.Save("Information.xml");
}
However whenever it gets to Doc.Load it gives me the following error:
NullReferenceException: Unexpected node type EndElement.
System.Xml.XmlDocument.ReadNodeCore (System.Xml.XmlReader reader)
System.Xml.XmlDocument.ReadNode (System.Xml.XmlReader reader)
System.Xml.XmlDocument.Load (System.Xml.XmlReader xmlReader)
selectNeighborhood.OnGUI () (at Assets/scripts/GUI Scripts/selectNeighborhood.js:145)
Does anyone know why?
Additional info if needed:
xmlRead is defined as:
var readerSettings = new XmlReaderSettings();
readerSettings.IgnoreWhitespace = true;
readerSettings.IgnoreComments = true;
var xmlRead= XmlReader.Create("Information.xml",readerSettings);
Thanks guys and gals,