Good morning , I have a template file written as XML file in this way
<Simulation>
<Pedestrian Name="Mother">
<Initial_Position In_X="3" In_Y="3" />
<Final_Position>
<First Fin_X="6" Fin_Y="6" Time="2" />
</Final_Position>
</Pedestrian>
I implemented a Class in order to read the file.
while (reader.Read() || i<Number_of_pedestrian)
{
if (reader.Name == "Pedestrian")
{
if (reader.HasAttributes == true)
{
name = reader.GetAttribute("Name");
//MessageBox.Show(name);
}
}
if(reader.Name == "Initial_Position")
{
if (reader.GetAttribute("In_X") != null && reader.GetAttribute("In_Y") != null)
{
X1 = int.Parse(reader.GetAttribute("In_X"));
Y1 = int.Parse(reader.GetAttribute("In_Y"));
}
}
if (reader.Name == "Initial_Position")
{
if (reader.GetAttribute("Fin_X") != null && reader.GetAttribute("Fin_Y") != null)
{
X2 = int.Parse(reader.GetAttribute("Fin_X"));
Y2 = int.Parse(reader.GetAttribute("Fin_Y"));
}
}
//Position Initial_Position = new Position (X1,Y1);
//Position Final_Position = new Position(X2, Y2);
Pd[i]=new Pedestrian (name, X1, Y1, X2, Y2);
Pd[i].Draw();
i++;
}
Which is able to read any attribute (in this case "Name") but is no able to read inside a node and then take the attribute (in this case inside "Initial_Position" and then "In_X").
Moreover the line Pd[i]=new Pedestrian (name, X1, Y1, X2, Y2);
give me the following error :
System.IndexOutOfRangeException occurs.
Additional Information : index over limits of matrix