public void ToXml(XmlWriter w) { int pathEnd = worldFilePath.LastIndexOf('\\'); string pathName = worldFilePath.Substring(0, pathEnd); w.WriteStartElement("World"); w.WriteAttributeString("Name", name); w.WriteAttributeString("Version", app.Config.XmlSaveFileVersion.ToString()); w.WriteStartElement("CameraPosition"); w.WriteAttributeString("x", cameraPosition.x.ToString()); w.WriteAttributeString("y", cameraPosition.y.ToString()); w.WriteAttributeString("z", cameraPosition.z.ToString()); w.WriteEndElement(); w.WriteStartElement("CameraOrientation"); w.WriteAttributeString("x", cameraOrientation.x.ToString()); w.WriteAttributeString("y", cameraOrientation.y.ToString()); w.WriteAttributeString("z", cameraOrientation.z.ToString()); w.WriteAttributeString("w", cameraOrientation.w.ToString()); w.WriteEndElement(); worldTerrain.ToXml(w); ocean.ToXml(w); skybox.ToXml(w); fog.ToXml(w); ambientLight.ToXml(w); directionalLight.ToXml(w); pathObjectTypes.ToXml(w); foreach (WorldObjectCollection worldCollection in worldCollections) { // write the XML into the top level world file w.WriteStartElement("WorldCollection"); worldCollection.Path = pathName; if (worldCollection.Filename == "") { int startIndex = pathEnd + 1; worldCollection.Path = pathName; int subStringLength = worldFilePath.LastIndexOf(".mvw") - startIndex + 4; worldCollection.Filename = String.Format("{0}-{1}.mwc", worldFilePath.Substring(startIndex, subStringLength), worldCollection.Name); } w.WriteAttributeString("Name", worldCollection.Name); w.WriteAttributeString("Filename", worldCollection.Filename); w.WriteEndElement(); // create a file for the collection if (worldCollection.Loaded) { try { XmlWriter childWriter = XmlWriter.Create(String.Format("{0}\\{1}", pathName, worldCollection.Filename), app.XMLWriterSettings); worldCollection.ToXml(childWriter); childWriter.Close(); } catch (Exception e) { LogManager.Instance.Write(e.ToString()); MessageBox.Show(String.Format("Unable to open the file for writing. Use file menu \"Save As\" to save to another location. Error: {0}", e.Message), "Error Saving File", MessageBoxButtons.OK); } } } w.WriteEndElement(); }