."/> ."/> "/>
خرید بک لینک

Vote count: 0

The XML file is as follows

<?xml version="1.0" encoding="utf-8" ?>
<Polygons>    
  <Polygon>
    <Points>
      <Point2D X="0" Y="0" />
      <Point2D X="100" Y="0" />
      <Point2D X="100" Y="200" />
      <Point2D X="0" Y="200" />
    </Points>
  </Polygon>
  <Polygon>
    <Points>
      <Point2D X="0" Y="0" />
      <Point2D X="100" Y="0" />
      <Point2D X="100" Y="200" />
      <Point2D X="0" Y="200" />
    </Points>
  </Polygon>
</Polygons>

I want to deserialize this XML back into Polygon objects. My Polygon class is as follows

[XmlType("Polygon")]
public class Polygon
{
    [XmlElement("Points")]
    public Point[] points { get; set; }
}

My deserialization code is

XmlSerializer serializer = new XmlSerializer(typeof(Polygon[]),new XmlRootAttribute("Polygons"));
FileStream fs = new FileStream(filename, FileMode.Open);
XmlReader reader = XmlReader.Create(fs);
Polygon[] p;
p = (Polygon[])serializer.Deserialize(reader);
fs.Close();

I've so far managed a workaround by creating a Point2D class with X and Y attributes and then creating Point objects using them. Is there any way to directly assign the attributes listed under Point2D to Point objects like pointObject.X and pointObject.Y?

asked 1 min ago

برچسب: نویسنده: استخدام کار تاريخ: جمعه 14 خرداد 1395 ساعت: 12:49

صفحه بندی