private void buttonSaveXML_Click(object sender, RoutedEventArgs e) { SaveFileDialog saveFileDlg1 = new SaveFileDialog(); saveFileDlg1.Filter = "Cave|*.cave|all|*.*"; saveFileDlg1.ShowDialog(); if (saveFileDlg1.SafeFileName != "") { System.IO.Stream stream = saveFileDlg1.OpenFile(); GenGFXtoXML(stream); stream.Flush(); stream.Close(); } }
функция GenGFXtoXML - генерирует XML файл и сохраняет его в поток stream
public void GenGFXtoXML(System.IO.Stream stream) { StringWriter sw = new StringWriter(); XmlWriterSettings settings = new XmlWriterSettings(); settings.Indent = true; //settings.NewLineOnAttributes = true; settings.ConformanceLevel = ConformanceLevel.Document; settings.OmitXmlDeclaration = true; using (XmlWriter xml = XmlWriter.Create(sw, settings)) { xml.WriteStartDocument(); xml.WriteComment("Создано WebPiket ver " + version); xml.WriteStartElement("gfx"); #region Линия масштаба line_scale Line lnscale = (Line)cnvDrawPoly.Children[3];// линия масштаба xml.WriteStartElement("lnscale"); xml.WriteStartAttribute("Name"); xml.WriteString(lnscale.Name); xml.WriteEndAttribute(); xml.WriteStartAttribute("X1"); xml.WriteString(lnscale.X1.ToString()); xml.WriteEndAttribute(); xml.WriteStartAttribute("Y1"); xml.WriteString(lnscale.Y1.ToString()); xml.WriteEndAttribute(); xml.WriteStartAttribute("X2"); xml.WriteString(lnscale.X2.ToString()); xml.WriteEndAttribute(); xml.WriteStartAttribute("Y2"); xml.WriteString(lnscale.Y2.ToString()); xml.WriteEndAttribute(); xml.WriteEndElement();//lnscale #endregion Линия масштаба line_scale #region Генератор XML // ..................... #endregion Генератор XML xml.WriteEndElement();//gfx xml.WriteEndDocument(); xml.Close(); } //Сохранение в файл using (StreamWriter writer = new StreamWriter(stream)) { writer.Write(sw); writer.Flush(); writer.Close(); } }
<!--Создано WebPiket ver 1.20100817.1811--> <gfx> <lnscale Name="line_Scale" X1="978" Y1="813" X2="982" Y2="817" /> <surve Name="surve_top_1"> <GeometryGroup> <LineGeometry X1="486,149658203125" Y1="412,589233398438" X2="495,5" Y2="409" /> <LineGeometry X1="491,280883789063" Y1="412,0654296875" X2="495,5" Y2="409" /> </GeometryGroup> </surve> <surve Name="surve_top_wall2"> <GeometryGroup> <LineGeometry X1="486,149658203125" Y1="412,589233398438" X2="495,5" Y2="409" /> <LineGeometry X1="491,280883789063" Y1="412,0654296875" X2="495,5" Y2="409" /> <LineGeometry X1="483,647216796875" Y1="418,938720703125" X2="491,280883789063" Y2="412,0654296875" /> <LineGeometry X1="493,34228515625" Y1="439,4326171875" X2="486,149658203125" Y2="412,589233398438" /> <LineGeometry X1="493,34228515625" Y1="439,4326171875" X2="483,1494140625" Y2="418,533813476563" /> </GeometryGroup> </surve> <polyline Name="polyline_3"> <point X="1040" Y="1039" /> <point X="1046" Y="1040" /> <point X="1054" Y="1036" /> <point X="1071" Y="1023" /> </polyline>
<line Name="line_4" X1="156" Y1="333" X2="246" Y2="237" /> </gfx>
Комментариев нет:
Отправить комментарий