comparison api/Factories/Xml/WarFoundryXmlFactory.cs @ 126:d5fec0698026

Fixes #113: XML loader doesn't close stream * Close stream after XML loading to allow re-saving file
author IBBoard <dev@ibboard.co.uk>
date Mon, 24 Aug 2009 21:20:36 +0000
parents 2f3cafb69799
children a37cdcbcad14
comparison
equal deleted inserted replaced
125:c60fd5664698 126:d5fec0698026
73 return armyFactory.CreateArmyFromElement(file, elem); 73 return armyFactory.CreateArmyFromElement(file, elem);
74 } 74 }
75 75
76 private XmlElement GetRootElementFromStream(Stream stream, WarFoundryXmlElementName elementName) 76 private XmlElement GetRootElementFromStream(Stream stream, WarFoundryXmlElementName elementName)
77 { 77 {
78 XmlDocument doc = WarFoundryXmlFactoryUtils.CreateXmlDocumentFromStream(stream); 78 XmlDocument doc = WarFoundryXmlFactoryUtils.CreateXmlDocumentFromStream(stream);
79 stream.Close();
79 XmlElement elem = (XmlElement)doc.LastChild; 80 XmlElement elem = (XmlElement)doc.LastChild;
80 81
81 if (!elem.LocalName.Equals(elementName.Value)) 82 if (!elem.LocalName.Equals(elementName.Value))
82 { 83 {
83 throw new InvalidFileException(String.Format("Root element of XML was not valid. Expected {0} but got {1}", elementName.Value, elem.Name)); 84 throw new InvalidFileException(String.Format("Root element of XML was not valid. Expected {0} but got {1}", elementName.Value, elem.Name));