I use this code to save:
XmlTextWriter writer = new XmlTextWriter(fileName, null);
writer.WriteStartDocument();
writer.WriteStartElement("CollisionGeom");
foreach (Rectangle rect in rects)
{
writer.WriteStartElement("Rect");
writer.WriteAttributeString("x", rect.X.ToString());
writer.WriteAttributeString("y", rect.Y.ToString());
writer.WriteAttributeString("width", rect.Width.ToString());
writer.WriteAttributeString("height", rect.Height.ToString());
writer.WriteEndElement();
}
writer.WriteEndElement();
writer.WriteEndDocument();
and this code to load: XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(fileName);
XmlNodeList xmlRects = xmlDoc.SelectNodes("CollisionGeom");
foreach (XmlNode xmlRect in xmlRects)
{
int x = int.Parse(xmlRect.Attributes["x"].Value);
int y = int.Parse(xmlRect.Attributes["y"].Value);
int width = int.Parse(xmlRect.Attributes["width"].Value);
int height = int.Parse(xmlRect.Attributes["height"].Value);
Rectangle rect = new Rectangle(x, y, width, height);
rects.Add(rect);
Graphics formGraphics = this.CreateGraphics();
SolidBrush myBrush = new SolidBrush(Color.Blue);
formGraphics.FillRectangle(myBrush, rect);
}
But the "xmlDoc.Load(fileName);" throws an exception that says the root element is missing. Obviously the problem is in the Save method somewhere, but no matter how many times I look, I must just miss it:crying:. li'l help please.


Sign In
Create Account


Back to top









