I want to read XML like this.
<?xml version="1.0" encoding="utf-8" ?>
<parent>
<path>
<pathPoints>
<point>
2 0
</point>
<point>
2 1
</point>
3 1
<point>
3 2
</point>
<point>
4 2
</point>
<point>
4 4
</point>
<point>
3 4
</point>
<point>
3 5
</point>
<point>
2 5
</point>
<point>
2 7
</point>
<point>
7 7
</point>
<point>
7 5
</point>
<point>
10 5
</point>
<point>
10 2
<point>
</point>
15 2
</point>
<point>
15 6
</point>
<point>
16 6
</point>
<point>
16 7
</point>
<point>
17 7
</point>
<point>
17 10
</point>
<point>
19 10
</point>
</pathPoints>
</parent>
</path>
And now I'm trying to read it:
paths = (from path in doc.Descendants("path")
select new AIPath()
{
waypoints = (from i in path.Descendants("pathPoints")
{
int j = Convert.ToInt32(i.Element("point").Value),
}).ToList();
}
).ToList();
My AIPath contains a list of vector2 called waypoints.
What I want to know is what I'm doing wrong. I want to create a new path everytime it changes which path it's looking at, which looks fine. What I'm confused about though is waht to do next. After the waypoints = (from i in path.Descendants("pathPoints"), I'm expecting i have to do something but I'm clueless as to what.
Any help would be greatly appreciated.
Edit
One or two details I forgot to add.
public class AIPath
{
//public Vector2
public List<Vector2> waypoints { get; set; }
public int linkNumber { get; set; }
public int[] potentialLinks { get; set; }
}
AIPathtype looks like, which makes it hard to help. Also, you haven't told us what your current code does. (It looks like it's basically a syntax error...)pointelement as a single integer, when it clearly contains two integers. Are you able to change the XML format? It looks like it would be much cleaner if the two values were set as attributes of thepointelements...