//ArrayList openElements = new ArrayList(); public void SerializeXml(IList<StarSystem> starSystems) { MemoryStream memXmlStream = new MemoryStream(); XmlSerializer serializer = new XmlSerializer(starSystems.GetType(), null, new Type[] { typeof(Planet), typeof(StarSystem) }, new XmlRootAttribute("Stars"), null, null); serializer.Serialize(memXmlStream, starSystems); XmlDocument xmlDoc = new XmlDocument(); memXmlStream.Seek(0, SeekOrigin.Begin); xmlDoc.Load(memXmlStream); XmlProcessingInstruction newPI; String PItext = string.Format("type='text/xsl' href='{0}'", "system.xslt"); newPI = xmlDoc.CreateProcessingInstruction("xml-stylesheet", PItext); xmlDoc.InsertAfter(newPI, xmlDoc.FirstChild); // Now write the document // out to the final output stream XmlTextWriter wr = new XmlTextWriter("system.xml", System.Text.Encoding.ASCII); wr.Formatting = Formatting.Indented; wr.IndentChar = '\t'; wr.Indentation = 1; XmlWriterSettings settings = new XmlWriterSettings(); XmlWriter writer = XmlWriter.Create(wr, settings); xmlDoc.WriteTo(writer); writer.Flush(); //Console.Write(xmlDoc.InnerXml); }
private void Init(string rootName) { try { doc = new XmlDocument(); var dec = doc.CreateNode(XmlNodeType.XmlDeclaration, "", ""); doc.InsertAfter(dec, null); root = doc.CreateNode(XmlNodeType.Element, rootName, ""); doc.InsertAfter(root, dec); } catch { } }
/// <summary> /// Formats the provided XML so it's indented and humanly-readable. /// </summary> /// <param name="inputXml">The input XML to format.</param> /// <returns></returns> public static string FormatXml(XmlElement element) { XmlDocument document = new XmlDocument(); var node = document.ImportNode(element, true); document.InsertAfter(node, null); StringBuilder builder = new StringBuilder(); var xmlSettings = new XmlWriterSettings { Indent = true, IndentChars = @" ", NewLineChars = Environment.NewLine, NewLineHandling = NewLineHandling.Replace, OmitXmlDeclaration = true, Encoding = Encoding.UTF8, }; using (var writer = XmlWriter.Create(builder, xmlSettings)) { document.Save(writer); } return builder.ToString(); }
private void Save3DPoints(Stream file, string path) { XmlDocument dataDoc = new XmlDocument(); var rootNode = dataDoc.CreateElement("Points"); for(int i= 0; i < _points3D.Count; ++i) { var point3D = _points3D[i]; var pointImg = _left[i]; var pointNode = dataDoc.CreateElement("Point"); var attRealX = dataDoc.CreateAttribute("realx"); attRealX.Value = point3D.At(0).ToString(); var attRealY = dataDoc.CreateAttribute("realy"); attRealY.Value = point3D.At(1).ToString(); var attRealZ = dataDoc.CreateAttribute("realz"); attRealZ.Value = point3D.At(2).ToString(); var attImgX = dataDoc.CreateAttribute("imgx"); attImgX.Value = pointImg.At(0).ToString(); var attImgY = dataDoc.CreateAttribute("imgy"); attImgY.Value = pointImg.At(1).ToString(); pointNode.Attributes.Append(attRealX); pointNode.Attributes.Append(attRealY); pointNode.Attributes.Append(attRealZ); pointNode.Attributes.Append(attImgX); pointNode.Attributes.Append(attImgY); rootNode.AppendChild(pointNode); } dataDoc.InsertAfter(rootNode, dataDoc.DocumentElement); dataDoc.Save(file); }
public void SaveDictToXML(String xmlFileName) { XmlDocument doc = new XmlDocument(); XmlNode docNode = doc.CreateXmlDeclaration("1.0", "UTF-8", null); doc.AppendChild(docNode); XmlWhitespace xml_declaration_newLine = doc.CreateWhitespace("\r\n"); doc.InsertAfter(xml_declaration_newLine, docNode); XmlNode tourNode = doc.CreateElement("TourStoryboard"); XmlAttribute tourNode_displayName = doc.CreateAttribute("displayName"); XmlAttribute tourNode_description = doc.CreateAttribute("description"); //// duratoin experiment XmlAttribute tourNode_duration = doc.CreateAttribute("duration"); tourNode_duration.Value = tourStoryboard.totalDuration.ToString(); tourNode.Attributes.Append(tourNode_duration); tourNode_displayName.Value = tourStoryboard.displayName; tourNode_description.Value = tourStoryboard.description; tourNode.Attributes.Append(tourNode_displayName); tourNode.Attributes.Append(tourNode_description); doc.AppendChild(tourNode); foreach (Timeline tl in tourBiDictionary.firstKeys) { TourTL tourTL = (TourTL)tl; BiDictionary<double, TourEvent> tourTL_dict = tourBiDictionary[tl][0]; if ((tourTL.type == TourTLType.artwork) || (tourTL.type == TourTLType.media) || tourTL.type == TourTLType.highlight || tourTL.type == TourTLType.path) { XmlNode TLNode = doc.CreateElement("TourParallelTL"); XmlAttribute TLNode_type = doc.CreateAttribute("type"); XmlAttribute TLNode_displayName = doc.CreateAttribute("displayName"); XmlAttribute TLNode_file = doc.CreateAttribute("file"); TLNode_type.Value = tourTL.type.ToString(); TLNode_displayName.Value = tourTL.displayName; TLNode_file.Value = tourTL.file; TLNode.Attributes.Append(TLNode_type); TLNode.Attributes.Append(TLNode_displayName); TLNode.Attributes.Append(TLNode_file); tourNode.AppendChild(TLNode); foreach (double beginTime in tourTL_dict.firstKeys) { TourEvent tourEvent = tourTL_dict[beginTime][0]; if (tourEvent.type == TourEvent.Type.zoomMSI) { ZoomMSIEvent zoomMSIEvent = (ZoomMSIEvent)tourEvent; XmlNode TourEventNode = doc.CreateElement("TourEvent"); XmlAttribute TourEventNode_beginTime = doc.CreateAttribute("beginTime"); XmlAttribute TourEventNode_type = doc.CreateAttribute("type"); XmlAttribute TourEventNode_scale = doc.CreateAttribute("scale"); XmlAttribute TourEventNode_toMSIPointX = doc.CreateAttribute("toMSIPointX"); XmlAttribute TourEventNode_toMSIPointY = doc.CreateAttribute("toMSIPointY"); XmlAttribute TourEventNode_duration = doc.CreateAttribute("duration"); TourEventNode_beginTime.Value = beginTime.ToString(); TourEventNode_type.Value = "ZoomMSIEvent"; TourEventNode_scale.Value = zoomMSIEvent.absoluteScale.ToString(); TourEventNode_toMSIPointX.Value = zoomMSIEvent.zoomToMSIPointX.ToString(); TourEventNode_toMSIPointY.Value = zoomMSIEvent.zoomToMSIPointY.ToString(); TourEventNode_duration.Value = zoomMSIEvent.duration.ToString(); TourEventNode.Attributes.Append(TourEventNode_beginTime); TourEventNode.Attributes.Append(TourEventNode_type); TourEventNode.Attributes.Append(TourEventNode_scale); TourEventNode.Attributes.Append(TourEventNode_toMSIPointX); TourEventNode.Attributes.Append(TourEventNode_toMSIPointY); TourEventNode.Attributes.Append(TourEventNode_duration); TLNode.AppendChild(TourEventNode); } else if (tourEvent.type == TourEvent.Type.fadeInMedia) { FadeInMediaEvent fadeInMediaEvent = (FadeInMediaEvent)tourEvent; XmlNode TourEventNode = doc.CreateElement("TourEvent"); XmlAttribute TourEventNode_beginTime = doc.CreateAttribute("beginTime"); XmlAttribute TourEventNode_type = doc.CreateAttribute("type"); XmlAttribute TourEventNode_toScreenPointX = doc.CreateAttribute("toScreenPointX"); XmlAttribute TourEventNode_toScreenPointY = doc.CreateAttribute("toScreenPointY"); XmlAttribute TourEventNode_scale = doc.CreateAttribute("scale"); XmlAttribute TourEventNode_duration = doc.CreateAttribute("duration"); TourEventNode_beginTime.Value = beginTime.ToString(); TourEventNode_type.Value = "FadeInMediaEvent"; TourEventNode_toScreenPointX.Value = fadeInMediaEvent.fadeInMediaToScreenPointX.ToString(); TourEventNode_toScreenPointY.Value = fadeInMediaEvent.fadeInMediaToScreenPointY.ToString(); TourEventNode_scale.Value = fadeInMediaEvent.absoluteScale.ToString(); TourEventNode_duration.Value = fadeInMediaEvent.duration.ToString(); TourEventNode.Attributes.Append(TourEventNode_beginTime); TourEventNode.Attributes.Append(TourEventNode_type); TourEventNode.Attributes.Append(TourEventNode_toScreenPointX); TourEventNode.Attributes.Append(TourEventNode_toScreenPointY); TourEventNode.Attributes.Append(TourEventNode_scale); TourEventNode.Attributes.Append(TourEventNode_duration); TLNode.AppendChild(TourEventNode); } else if (tourEvent.type == TourEvent.Type.fadeOutMedia) { FadeOutMediaEvent fadeOutMediaEvent = (FadeOutMediaEvent)tourEvent; XmlNode TourEventNode = doc.CreateElement("TourEvent"); XmlAttribute TourEventNode_beginTime = doc.CreateAttribute("beginTime"); XmlAttribute TourEventNode_type = doc.CreateAttribute("type"); XmlAttribute TourEventNode_duration = doc.CreateAttribute("duration"); TourEventNode_beginTime.Value = beginTime.ToString(); TourEventNode_type.Value = "FadeOutMediaEvent"; TourEventNode_duration.Value = fadeOutMediaEvent.duration.ToString(); TourEventNode.Attributes.Append(TourEventNode_beginTime); TourEventNode.Attributes.Append(TourEventNode_type); TourEventNode.Attributes.Append(TourEventNode_duration); TLNode.AppendChild(TourEventNode); } else if (tourEvent.type == TourEvent.Type.zoomMedia) { ZoomMediaEvent zoomMediaEvent = (ZoomMediaEvent)tourEvent; XmlNode TourEventNode = doc.CreateElement("TourEvent"); XmlAttribute TourEventNode_beginTime = doc.CreateAttribute("beginTime"); XmlAttribute TourEventNode_type = doc.CreateAttribute("type"); XmlAttribute TourEventNode_scale = doc.CreateAttribute("scale"); XmlAttribute TourEventNode_toScreenPointX = doc.CreateAttribute("toScreenPointX"); XmlAttribute TourEventNode_toScreenPointY = doc.CreateAttribute("toScreenPointY"); XmlAttribute TourEventNode_duration = doc.CreateAttribute("duration"); TourEventNode_beginTime.Value = beginTime.ToString(); TourEventNode_type.Value = "ZoomMediaEvent"; TourEventNode_scale.Value = zoomMediaEvent.absoluteScale.ToString(); TourEventNode_toScreenPointX.Value = zoomMediaEvent.zoomMediaToScreenPointX.ToString(); TourEventNode_toScreenPointY.Value = zoomMediaEvent.zoomMediaToScreenPointY.ToString(); TourEventNode_duration.Value = zoomMediaEvent.duration.ToString(); TourEventNode.Attributes.Append(TourEventNode_beginTime); TourEventNode.Attributes.Append(TourEventNode_type); TourEventNode.Attributes.Append(TourEventNode_scale); TourEventNode.Attributes.Append(TourEventNode_toScreenPointX); TourEventNode.Attributes.Append(TourEventNode_toScreenPointY); TourEventNode.Attributes.Append(TourEventNode_duration); TLNode.AppendChild(TourEventNode); } else if (tourEvent.type == TourEvent.Type.fadeInHighlight) { FadeInHighlightEvent fadeInHighlightEvent = (FadeInHighlightEvent)tourEvent; XmlNode TourEventNode = doc.CreateElement("TourEvent"); XmlAttribute TourEventNode_beginTime = doc.CreateAttribute("beginTime"); XmlAttribute TourEventNode_type = doc.CreateAttribute("type"); XmlAttribute TourEventNode_duration = doc.CreateAttribute("duration"); XmlAttribute TourEventNode_opacity = doc.CreateAttribute("opacity"); TourEventNode_beginTime.Value = beginTime.ToString(); TourEventNode_type.Value = "FadeInHighlightEvent"; TourEventNode_duration.Value = fadeInHighlightEvent.duration.ToString(); TourEventNode_opacity.Value = fadeInHighlightEvent.opacity.ToString(); TourEventNode.Attributes.Append(TourEventNode_beginTime); TourEventNode.Attributes.Append(TourEventNode_type); TourEventNode.Attributes.Append(TourEventNode_duration); TourEventNode.Attributes.Append(TourEventNode_opacity); TLNode.AppendChild(TourEventNode); } else if (tourEvent.type == TourEvent.Type.fadeOutHighlight) { FadeOutHighlightEvent fadeOutHighlightEvent = (FadeOutHighlightEvent)tourEvent; XmlNode TourEventNode = doc.CreateElement("TourEvent"); XmlAttribute TourEventNode_beginTime = doc.CreateAttribute("beginTime"); XmlAttribute TourEventNode_type = doc.CreateAttribute("type"); XmlAttribute TourEventNode_duration = doc.CreateAttribute("duration"); XmlAttribute TourEventNode_opacity = doc.CreateAttribute("opacity"); TourEventNode_beginTime.Value = beginTime.ToString(); TourEventNode_type.Value = "FadeOutHighlightEvent"; TourEventNode_duration.Value = fadeOutHighlightEvent.duration.ToString(); TourEventNode_opacity.Value = fadeOutHighlightEvent.opacity.ToString(); TourEventNode.Attributes.Append(TourEventNode_beginTime); TourEventNode.Attributes.Append(TourEventNode_type); TourEventNode.Attributes.Append(TourEventNode_duration); TourEventNode.Attributes.Append(TourEventNode_opacity); TLNode.AppendChild(TourEventNode); } else if (tourEvent.type == TourEvent.Type.fadeInPath) { FadeInPathEvent fadeInPathEvent = (FadeInPathEvent)tourEvent; XmlNode TourEventNode = doc.CreateElement("TourEvent"); XmlAttribute TourEventNode_beginTime = doc.CreateAttribute("beginTime"); XmlAttribute TourEventNode_type = doc.CreateAttribute("type"); XmlAttribute TourEventNode_duration = doc.CreateAttribute("duration"); TourEventNode_beginTime.Value = beginTime.ToString(); TourEventNode_type.Value = "FadeInPathEvent"; TourEventNode_duration.Value = fadeInPathEvent.duration.ToString(); TourEventNode.Attributes.Append(TourEventNode_beginTime); TourEventNode.Attributes.Append(TourEventNode_type); TourEventNode.Attributes.Append(TourEventNode_duration); TLNode.AppendChild(TourEventNode); } else if (tourEvent.type == TourEvent.Type.fadeOutPath) { FadeOutPathEvent fadeOutPathEvent = (FadeOutPathEvent)tourEvent; XmlNode TourEventNode = doc.CreateElement("TourEvent"); XmlAttribute TourEventNode_beginTime = doc.CreateAttribute("beginTime"); XmlAttribute TourEventNode_type = doc.CreateAttribute("type"); XmlAttribute TourEventNode_duration = doc.CreateAttribute("duration"); TourEventNode_beginTime.Value = beginTime.ToString(); TourEventNode_type.Value = "FadeOutPathEvent"; TourEventNode_duration.Value = fadeOutPathEvent.duration.ToString(); TourEventNode.Attributes.Append(TourEventNode_beginTime); TourEventNode.Attributes.Append(TourEventNode_type); TourEventNode.Attributes.Append(TourEventNode_duration); TLNode.AppendChild(TourEventNode); } } } else if (tourTL.type == TourTLType.audio) { XmlNode TLNode = doc.CreateElement("TourMediaTL"); XmlAttribute TLNode_type = doc.CreateAttribute("type"); XmlAttribute TLNode_displayName = doc.CreateAttribute("displayName"); XmlAttribute TLNode_file = doc.CreateAttribute("file"); XmlAttribute TLNode_beginTime = doc.CreateAttribute("beginTime"); XmlAttribute TLNode_duration = doc.CreateAttribute("duration"); TLNode_type.Value = tourTL.type.ToString(); TLNode_displayName.Value = tourTL.displayName; TLNode_file.Value = tourTL.file; TLNode_beginTime.Value = ((TourMediaTL)tourTL).BeginTime.Value.TotalSeconds.ToString(); TLNode_duration.Value = ((TourMediaTL)tourTL).Duration.TimeSpan.TotalSeconds.ToString(); TLNode.Attributes.Append(TLNode_type); TLNode.Attributes.Append(TLNode_displayName); TLNode.Attributes.Append(TLNode_file); TLNode.Attributes.Append(TLNode_beginTime); TLNode.Attributes.Append(TLNode_duration); tourNode.AppendChild(TLNode); } } doc.Save(xmlFileName); }
public void SaveCalibMatched(Stream file, string path) { XmlDocument dataDoc = new XmlDocument(); var rootNode = dataDoc.CreateElement("Points"); var calibMatchedLeft = new List<CalibrationPoint>(CalibrationPointsLeft.Count); var calibMatchedRight = new List<CalibrationPoint>(CalibrationPointsRight.Count); for(int i = 0; i < CalibrationPointsLeft.Count; ++i) { var cleft = CalibrationPointsLeft[i]; var cright = CalibrationPointsRight.Find((cp) => { return cp.GridNum == cleft.GridNum && cp.RealCol == cleft.RealCol && cp.RealRow == cleft.RealRow; }); if(cright != null) { calibMatchedLeft.Add(cleft); calibMatchedRight.Add(cright); } } for(int i = 0; i < calibMatchedLeft.Count; ++i) { var cpL = calibMatchedLeft[i]; var cpR = calibMatchedRight[i]; var pointNode = dataDoc.CreateElement("Point"); var attImgX = dataDoc.CreateAttribute("imgx"); attImgX.Value = cpL.ImgX.ToString("F3"); var attImgY = dataDoc.CreateAttribute("imgy"); attImgY.Value = cpL.ImgY.ToString("F3"); var attImgX2 = dataDoc.CreateAttribute("imgx2"); attImgX2.Value = cpR.ImgX.ToString("F3"); var attImgY2 = dataDoc.CreateAttribute("imgy2"); attImgY2.Value = cpR.ImgY.ToString("F3"); pointNode.Attributes.Append(attImgX); pointNode.Attributes.Append(attImgY); pointNode.Attributes.Append(attImgX2); pointNode.Attributes.Append(attImgY2); rootNode.AppendChild(pointNode); } dataDoc.InsertAfter(rootNode, dataDoc.DocumentElement); dataDoc.Save(file); }
public void InsertAfter() { document = new XmlDocument(); document.LoadXml("<root><sub1 /><sub2 /></root>"); XmlElement docelem = document.DocumentElement; XmlElement newelem = document.CreateElement("good_child"); docelem.InsertAfter(newelem, docelem.FirstChild); AssertEquals("InsertAfter.Normal", 3, docelem.ChildNodes.Count); AssertEquals("InsertAfter.First", "sub1", docelem.FirstChild.Name); AssertEquals("InsertAfter.Last", "sub2", docelem.LastChild.Name); AssertEquals("InsertAfter.Prev", "good_child", docelem.FirstChild.NextSibling.Name); AssertEquals("InsertAfter.Next", "good_child", docelem.LastChild.PreviousSibling.Name); // this doesn't throw any exception *only on .NET 1.1* // .NET 1.0 throws an exception. try { document.InsertAfter(document.CreateElement("BAD_MAN"), docelem); #if USE_VERSION_1_1 AssertEquals("InsertAfter with bad location", "<root><sub1 /><good_child /><sub2 /></root><BAD_MAN />", document.InnerXml); } catch (XmlException ex) { throw ex; } #else } catch (Exception) {}
public void SaveToFile(Stream file, string path) { XmlDocument dataDoc = new XmlDocument(); var rootNode = dataDoc.CreateElement("Points"); foreach(var cpoint in _pointList) { var pointNode = dataDoc.CreateElement("Point"); var attImgX = dataDoc.CreateAttribute("imgx"); attImgX.Value = cpoint.ImgX.ToString("F3"); var attImgY = dataDoc.CreateAttribute("imgy"); attImgY.Value = cpoint.ImgY.ToString("F3"); var attGridNum = dataDoc.CreateAttribute("grid"); attGridNum.Value = cpoint.GridNum.ToString(); var attRow = dataDoc.CreateAttribute("gridRow"); attRow.Value = cpoint.RealRow.ToString(); var attCol = dataDoc.CreateAttribute("gridColumn"); attCol.Value = cpoint.RealCol.ToString(); var attRealX = dataDoc.CreateAttribute("realx"); attRealX.Value = cpoint.RealX.ToString("F3"); var attRealY = dataDoc.CreateAttribute("realy"); attRealY.Value = cpoint.RealY.ToString("F3"); var attRealZ = dataDoc.CreateAttribute("realz"); attRealZ.Value = cpoint.RealZ.ToString("F3"); pointNode.Attributes.Append(attImgX); pointNode.Attributes.Append(attImgY); pointNode.Attributes.Append(attGridNum); pointNode.Attributes.Append(attRow); pointNode.Attributes.Append(attCol); pointNode.Attributes.Append(attRealX); pointNode.Attributes.Append(attRealY); pointNode.Attributes.Append(attRealZ); rootNode.AppendChild(pointNode); } dataDoc.InsertAfter(rootNode, dataDoc.DocumentElement); dataDoc.Save(file); }
/// <summary> /// Get a string that contains a complete SVG document. XML version, DOCTYPE etc are included. /// </summary> /// <returns></returns> /// <param name="compressAttributes">Should usually be set true. Causes the XML output to be optimized so that /// long attributes like styles and transformations are represented with entities.</param> public string WriteSVGString(bool compressAttributes) { string s; string ents = ""; XmlDocument doc = new XmlDocument(); var declaration = doc.CreateXmlDeclaration("1.0", null, "yes"); doc.AppendChild(declaration); //write out our SVG tree to the new XmlDocument WriteXmlElements(doc, null); doc.DocumentElement.SetAttribute("xmlns", "http://www.w3.org/2000/svg"); if (compressAttributes) ents = SvgFactory.CompressXML(doc, doc.DocumentElement); doc.XmlResolver = new DummyXmlResolver(); doc.InsertAfter( doc.CreateDocumentType("svg", "-//W3C//DTD SVG 1.1//EN", "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd", ents), declaration ); //This complicated business of writing to a memory stream and then reading back out to a string //is necessary in order to specify UTF8 -- for some reason the default is UTF16 (which makes most renderers //give up) MemoryStream ms = new MemoryStream(); XmlTextWriter wr = new XmlTextWriter(ms, new UTF8Encoding()); wr.Formatting = Formatting.None; // Indented formatting would be nice for debugging but causes unwanted trailing white spaces between <text> and <tspan> elements in Internet Explorer doc.Save(wr); byte[] buf = ms.ToArray(); s = Encoding.UTF8.GetString(buf, 0, buf.Length); wr.Close(); return s; }
string addCheckSum(string xmlFileName, string chksum) { XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(xmlFileName); XmlComment chkSumComment; chkSumComment = xmlDoc.CreateComment("Checksum:" + chksum); XmlElement root = xmlDoc.DocumentElement; xmlDoc.InsertAfter(chkSumComment, root); xmlDoc.Save(xmlFileName); return chksum; }
protected static void ReGenerateSchema(XmlDocument xmlDoc) { string dtd = DocumentType.GenerateXmlDocumentType(); // remove current doctype XmlNode n = xmlDoc.FirstChild; while (n.NodeType != XmlNodeType.DocumentType && n.NextSibling != null) { n = n.NextSibling; } if (n.NodeType == XmlNodeType.DocumentType) { xmlDoc.RemoveChild(n); } XmlDocumentType docType = xmlDoc.CreateDocumentType("root", null, null, dtd); xmlDoc.InsertAfter(docType, xmlDoc.FirstChild); }
public static string UpdateProduct(string product, string buildNumber, string edition) { var prodDoc = new XmlDocument{XmlResolver = null}; prodDoc.Load(product); XmlProcessingInstruction lastOne = null; bool foundBuildNumber = false; bool foundEdition = false; Debug.Assert(prodDoc.DocumentElement != null, "prodDoc.DocumentElement != null"); foreach (var childNode in prodDoc.ChildNodes.Cast<XmlNode>().Where(childNode => childNode.NodeType == XmlNodeType.ProcessingInstruction).Cast<XmlProcessingInstruction>()) { if (childNode.Value.StartsWith("BUILD_NUMBER")) { childNode.Value = string.Format(@"BUILD_NUMBER=""{0}""", buildNumber); foundBuildNumber = true; } else if (childNode.Value.StartsWith("Edition")) { childNode.Value = string.Format(@"Edition=""{0}""", edition); foundEdition = true; } else { lastOne = childNode; } } if (!foundBuildNumber) { var verProcInst = prodDoc.CreateProcessingInstruction("define", string.Format(@"BUILD_NUMBER=""{0}""", buildNumber)); prodDoc.InsertAfter(verProcInst, lastOne); } if (!foundEdition) { var verProcInst = prodDoc.CreateProcessingInstruction("define", string.Format(@"Edition=""{0}""", edition)); prodDoc.InsertAfter(verProcInst, lastOne); } var tempName = Path.GetTempFileName(); var writer = XmlWriter.Create(tempName, new XmlWriterSettings {Indent = true, Encoding = Encoding.UTF8}); prodDoc.Save(writer); writer.Close(); return tempName; }
public XmlDocument SendQuestion(string sInput) { //kanoume to authentication gia to service ServiceAuthHeaderValidation.Validate(CustomSoapHeader); string username = null; string password = null; string prefix = null; string NamspaceURI = null; XmlDocument doc = new XmlDocument(); XmlDocument doc_out = new XmlDocument(); string con_string = WebConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString; SqlConnection con = new SqlConnection(con_string); string con_string_trust = WebConfigurationManager.ConnectionStrings["TrustMainConnectionString"].ConnectionString; SqlConnection con_trust = new SqlConnection(con_string_trust); try { XmlDeclaration xmlindeclaration = null; xmlindeclaration = doc.CreateXmlDeclaration("1.0", "utf-8", null); doc.InsertBefore(xmlindeclaration, doc.DocumentElement); doc.LoadXml(sInput); //diavazoume ta username password gia kathe customer username = System.Configuration.ConfigurationManager.AppSettings["username"]; password = System.Configuration.ConfigurationManager.AppSettings["password"]; prefix = System.Configuration.ConfigurationManager.AppSettings["prefix"]; NamspaceURI = System.Configuration.ConfigurationManager.AppSettings["NamspaceURI"]; //FTIAXNOUME TO XML_EKSODOU XmlDeclaration xmldeclaration = null; xmldeclaration = doc_out.CreateXmlDeclaration("1.0", "utf-8", null); doc_out.InsertBefore(xmldeclaration, doc_out.DocumentElement); XmlAttribute attr1 = doc_out.CreateAttribute("xmlns:"+prefix); attr1.Value = NamspaceURI; XmlElement root_element = null; root_element = doc_out.CreateElement(prefix, "EntityDetrimentalData", NamspaceURI); doc_out.InsertAfter(root_element, xmldeclaration); doc_out.DocumentElement.Attributes.Append(attr1); //VRISKOUME TO PELATH POU KANEI TO ERWTHMA SqlCommand cmd = null; cmd = new SqlCommand("SELECT_CUSTOMER", con); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add(new SqlParameter("@CUSTOMER_USERNAME", username)); cmd.Parameters.Add(new SqlParameter("@CUSTOMER_PASSWORD", password)); SqlParameter ID_PARAM = new SqlParameter("@CUSTOMER_ID", 0); ID_PARAM.Direction = ParameterDirection.Output; ID_PARAM.SqlDbType = SqlDbType.Int; cmd.Parameters.Add(ID_PARAM); int CUSTOMER_ID = 0; con.Open(); cmd.ExecuteNonQuery(); CUSTOMER_ID = (int)ID_PARAM.Value; con.Close(); //AN VRETHEI O PELATHS DIAVAZOUME TA STOIXEIA TOU ERWTHMATOS if (CUSTOMER_ID != 0) { XmlNodeList list = doc.SelectNodes("//XML/PERSONCOMPANIES"); string output = ""; foreach (XmlNode NODE in list) { con.Open(); XmlDocument doc1 = new XmlDocument(); doc1.LoadXml(NODE.InnerXml); int QUESTION_ID = 0; string personcompanyid = doc1.SelectSingleNode("PERSONCOMPANY/PERSONCOMPANYID").InnerXml; string lastname = doc1.SelectSingleNode("PERSONCOMPANY/LASTNAME").InnerXml; string firstname = doc1.SelectSingleNode("PERSONCOMPANY/FIRSTNAME").InnerXml; string fathername = doc1.SelectSingleNode("PERSONCOMPANY/FATHERNAME").InnerXml; string companyname = doc1.SelectSingleNode("PERSONCOMPANY/COMPANYNAME").InnerXml; string IDCARD = ""; if ((doc1.SelectSingleNode("PERSONCOMPANY/IDCARD")) is XmlNode) { IDCARD = doc1.SelectSingleNode("PERSONCOMPANY/IDCARD").InnerXml; } string TAXNUMBER = doc1.SelectSingleNode("PERSONCOMPANY/TAXNUMBER").InnerXml; if ((doc1.SelectSingleNode("PERSONCOMPANY/IDCARD")) is XmlNode) { IDCARD = doc1.SelectSingleNode("PERSONCOMPANY/IDCARD").InnerXml; } string address = doc1.SelectSingleNode("PERSONCOMPANY/ADDRESS").InnerXml; string CITY = doc1.SelectSingleNode("PERSONCOMPANY/CITY").InnerXml; string COUNTY = doc1.SelectSingleNode("PERSONCOMPANY/COUNTY").InnerXml; string PHONE = doc1.SelectSingleNode("PERSONCOMPANY/PHONE").InnerXml; string POSTCODE = ""; if ((doc1.SelectSingleNode("PERSONCOMPANY/POSTCODE")) is XmlNode) { POSTCODE = doc1.SelectSingleNode("PERSONCOMPANY/POSTCODE").InnerXml; } //EISAGOUME TO ERWTHMA cmd = new SqlCommand("INSERT_QUESTION", con); cmd.CommandType = CommandType.StoredProcedure; SqlParameter ID_PARAM_QUESTION = new SqlParameter("@QUESTION_ID", 0); ID_PARAM_QUESTION.Direction = ParameterDirection.Output; ID_PARAM_QUESTION.SqlDbType = SqlDbType.Int; cmd.Parameters.Add(ID_PARAM_QUESTION); if (!string.IsNullOrEmpty(personcompanyid)) { cmd.Parameters.Add(new SqlParameter("@VODAFONE_CODE", personcompanyid)); } if (!string.IsNullOrEmpty(lastname)) { cmd.Parameters.Add(new SqlParameter("@LASTNAME", lastname)); } if (!string.IsNullOrEmpty(firstname)) { cmd.Parameters.Add(new SqlParameter("@FIRSTNAME", firstname)); } if (!string.IsNullOrEmpty(fathername)) { cmd.Parameters.Add(new SqlParameter("@FATHERNAME", fathername)); } if (!string.IsNullOrEmpty(companyname)) { cmd.Parameters.Add(new SqlParameter("@COMPANYNAME", companyname)); } if (!string.IsNullOrEmpty(IDCARD)) { cmd.Parameters.Add(new SqlParameter("@IDCARD", IDCARD)); } if (!string.IsNullOrEmpty(TAXNUMBER)) { cmd.Parameters.Add(new SqlParameter("@TAXNUMBER", TAXNUMBER)); } if (!string.IsNullOrEmpty(address)) { cmd.Parameters.Add(new SqlParameter("@ADDRESS", address)); } if (!string.IsNullOrEmpty(CITY)) { cmd.Parameters.Add(new SqlParameter("@CITY", CITY)); } if (!string.IsNullOrEmpty(COUNTY)) { cmd.Parameters.Add(new SqlParameter("@COUNTY", COUNTY)); } if (!string.IsNullOrEmpty(PHONE)) { cmd.Parameters.Add(new SqlParameter("@PHONE", PHONE)); } if (!string.IsNullOrEmpty(POSTCODE)) { cmd.Parameters.Add(new SqlParameter("@POSTCODE", POSTCODE)); } cmd.Parameters.Add(new SqlParameter("@CUSTOMER_ID", CUSTOMER_ID)); cmd.Parameters.Add(new SqlParameter("@INPUT", sInput)); cmd.ExecuteNonQuery(); QUESTION_ID = (int) ID_PARAM_QUESTION.Value; con.Close(); //PROETOIMASIA APANTHSHS XmlElement xmlpr_cmpname = null; xmlpr_cmpname = doc_out.CreateElement(prefix, "entityName", NamspaceURI); XmlElement xmlpr_cmptype = null; xmlpr_cmptype = doc_out.CreateElement(prefix, "entityType", NamspaceURI); XmlElement xmlpr_vat = null; xmlpr_vat = doc_out.CreateElement(prefix,"vatNumber",NamspaceURI); //PSAXNOUME STO INFO con_trust.Open(); //Vriskoume ta Details tou Company cmd = new SqlCommand("SELECT TOP 1 PRS_CMP_ID, CASE WHEN PRS_CMP_IS_COMPANY = 1 THEN 'COMPANY' ELSE 'INDIVIDUAL' END AS PRS_CMP_TYPE, (PRS_CMP_LASTNAME +' ' + PRS_CMP_FIRSTNAME )AS PRS_CMP_FULLNAME, PRS_CMP_COMPANY_NAME FROM PERSON_COMPANY WHERE PRS_CMP_AFM = '" + TAXNUMBER + "' AND PRS_CMP_ACTIVE = 1 AND PRS_CMP_NOVIEW = 0 AND PRS_CMP_RATED = 1 ", con_trust); cmd.CommandType = CommandType.Text; SqlDataReader read_rd; output = "False"; read_rd = cmd.ExecuteReader(); if (read_rd.HasRows) { while (read_rd.Read()) { xmlpr_cmpname.InnerText = read_rd["PRS_CMP_FULLNAME"].ToString() + read_rd["PRS_CMP_COMPANY_NAME"].ToString(); xmlpr_cmptype.InnerText = read_rd["PRS_CMP_TYPE"].ToString(); xmlpr_vat.InnerText = TAXNUMBER; } } read_rd.Close(); root_element.AppendChild(xmlpr_cmptype); root_element.AppendChild(xmlpr_vat); root_element.AppendChild(xmlpr_cmpname); cmd = new SqlCommand("REALCHECK_CMAPPL_VODAFONE3", con_trust); cmd.CommandType = CommandType.StoredProcedure; SqlDataReader READER = null; cmd.Parameters.Add(new SqlParameter("@PRS_CMP_AFM", TAXNUMBER)); READER = cmd.ExecuteReader(); while (READER.Read()) { output = "True"; XmlElement xmlresponse = null; xmlresponse = doc_out.CreateElement(prefix,"EntityDetrimentalRecord",NamspaceURI); XmlElement detrimentalType = null; detrimentalType = doc_out.CreateElement(prefix,"detrimentalType",NamspaceURI); detrimentalType.InnerText = READER["TRCS_INFO_CATEGORY"].ToString(); xmlresponse.AppendChild(detrimentalType); XmlElement detrimentalYear = null; detrimentalYear = doc_out.CreateElement(prefix,"detrimentalYear",NamspaceURI); detrimentalYear.InnerText = READER["TRCS_INFO_DATE_YEAR"].ToString(); xmlresponse.AppendChild(detrimentalYear); XmlElement detrimentalItems = null; detrimentalItems = doc_out.CreateElement(prefix, "detrimentalItems", NamspaceURI); detrimentalItems.InnerText = READER["TRCS_COUNTOF_ACTIVE"].ToString(); xmlresponse.AppendChild(detrimentalItems); XmlElement detrimentalValue = null; detrimentalValue = doc_out.CreateElement(prefix, "detrimentalValue", NamspaceURI); detrimentalValue.InnerText = READER["TRCS_SUMOF_ACTIVE"].ToString(); xmlresponse.AppendChild(detrimentalValue); XmlElement detrimentalSettledItems = null; detrimentalSettledItems = doc_out.CreateElement(prefix, "detrimentalSettledItems", NamspaceURI); detrimentalSettledItems.InnerText = READER["TRCS_COUNTOF_INACTIVE"].ToString(); xmlresponse.AppendChild(detrimentalSettledItems); XmlElement detrimentalSettledValue = null; detrimentalSettledValue = doc_out.CreateElement(prefix, "detrimentalSettledValue", NamspaceURI); detrimentalSettledValue.InnerText = READER["TRCS_SUMOF_INACTIVE"].ToString(); xmlresponse.AppendChild(detrimentalSettledValue); root_element.AppendChild(xmlresponse); } READER.Close(); con_trust.Close(); // KATAXWROUME THN APANTHSH con.Open(); cmd = new SqlCommand("INSERT_ANSWER", con); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add(new SqlParameter("@QUESTION_ID", QUESTION_ID)); cmd.Parameters.Add(new SqlParameter("@ANSWER_RESULT", output)); cmd.Parameters.Add(new SqlParameter("@ANSWER_XML", root_element.InnerXml)); cmd.ExecuteNonQuery(); con.Close(); } // doc_out.Save("c:\inetpub\wwwroot\vodafonewebservice\test.xml") return doc_out; //AN DEN VRETHEI PELATHS STELNOUME ERROR KAI PERNAME TO ERWTHMA SAN MH APANTHMENO } else { XmlDocument outXML = new XmlDocument(); outXML.InnerXml = "<XML><ERROR><MESSAGE>" + "CUSTOMER NOT FOUND, CHECK USERNAME AND PASSWORD" + "</MESSAGE></ERROR></XML>"; SaveError("CUSTOMER NOT FOUND, CHECK USERNAME AND PASSWORD", sInput); return outXML; } } catch (Exception ex) { XmlDocument outXML = new XmlDocument(); outXML.InnerXml = "<XML><ERROR><MESSAGE>" + ex.Message + "</MESSAGE></ERROR></XML>"; SaveError(ex.Message, sInput); return outXML; } finally { con.Close(); } }
public void SaveToFile(Stream file) { XmlDocument dataDoc = new XmlDocument(); var camerasNode = dataDoc.CreateElement("Cameras"); var cam1Node = dataDoc.CreateElement("Camera"); var cam1AttNum = dataDoc.CreateAttribute("num"); cam1AttNum.Value = "1"; var cam1AttCalib = dataDoc.CreateAttribute("is_calibrated"); cam1AttCalib.Value = IsCamLeftCalibrated.ToString(); cam1Node.Attributes.Append(cam1AttNum); cam1Node.Attributes.Append(cam1AttCalib); if (IsCamLeftCalibrated) { cam1Node.InnerText = CamMatrixToString(CameraLeft); } camerasNode.AppendChild(cam1Node); var cam2Node = dataDoc.CreateElement("Camera"); var cam2AttNum = dataDoc.CreateAttribute("num"); cam2AttNum.Value = "2"; var cam2AttCalib = dataDoc.CreateAttribute("is_calibrated"); cam2AttCalib.Value = IsCamRightCalibrated.ToString(); cam2Node.Attributes.Append(cam2AttNum); cam2Node.Attributes.Append(cam2AttCalib); if (IsCamRightCalibrated) { cam2Node.InnerText = CamMatrixToString(CameraRight); } camerasNode.AppendChild(cam2Node); dataDoc.InsertAfter(camerasNode, dataDoc.DocumentElement); dataDoc.Save(file); }
private void SaveMap(Stream file, string path) { XmlDocument xmlDoc = new XmlDocument(); XmlNode mapNode = Map.CreateMapNode(xmlDoc); xmlDoc.InsertAfter(mapNode, xmlDoc.DocumentElement); xmlDoc.Save(file); }
/// <summary> Writes the current input bindings to a file on disk. </summary> public void Store() { XmlDocument bindings = new XmlDocument(); XmlNode node; XmlElement element; XmlElement root = bindings.CreateElement("Save"); bindings.InsertAfter(root, bindings.DocumentElement); element = bindings.CreateElement("Count"); node = bindings.CreateTextNode("Count"); node.Value = weapons.Length + ""; element.AppendChild(node); root.AppendChild(element); for (int i = 0; i < weapons.Length; i++) { element = bindings.CreateElement("Bullet" + i); node = bindings.CreateTextNode("Bullet" + i); node.Value = weapons[i].ToString(); element.AppendChild(node); root.AppendChild(element); } bindings.Save(filename); }
public void SaveChart(String fileName) { foreach (DiagramNode box in chart.Nodes) { if (box is ShapeNode) { XMLNode node = new XMLNode((ShapeNode)box); Nodes.Add(node); } } // First serialize the document to an in-memory stream MemoryStream memXmlStream = new MemoryStream(); XmlSerializer serializer = new XmlSerializer(typeof(XMLChart)); try { serializer.Serialize(memXmlStream, this); } catch (Exception serError) { MessageBox.Show("ERROR SERIALIZING"); } // Now create a document with // the stylesheet processing instruction XmlDocument xmlDoc = new XmlDocument(); // Now load the in-memory stream // XML data into the XMl document memXmlStream.Seek(0, SeekOrigin.Begin); xmlDoc.Load(memXmlStream); // Now add the stylesheet processing // instruction to the XML document XmlProcessingInstruction newPI; String PItext = "type='text/xsl' href='ichart.xsl'"; newPI = xmlDoc.CreateProcessingInstruction("xml-stylesheet", PItext); xmlDoc.InsertAfter(newPI, xmlDoc.FirstChild); // Now write the document // out to the final output stream XmlTextWriter xmlWriter = new XmlTextWriter(fileName, System.Text.Encoding.UTF8); xmlWriter.Formatting = Formatting.Indented; xmlWriter.Indentation = 2; xmlDoc.WriteTo(xmlWriter); xmlWriter.Flush(); xmlWriter.Close(); //UtilIO.SaveXML(this, fileName, typeof(XmlChart)); }
//03-09-2008 public void CreateChild(ArrayList arrPrameter, DataSet dset, string rootNodeName, string Element, string foder, string fileName) { XmlDocument xmlDoc = new XmlDocument(); XmlDeclaration xmlDeclaration = xmlDoc.CreateXmlDeclaration("1.0", "utf-8", null); XmlElement rootNode = xmlDoc.CreateElement(rootNodeName); xmlDoc.InsertAfter(xmlDeclaration, xmlDoc.DocumentElement); xmlDoc.AppendChild(rootNode); for (int i = dset.Tables[0].Rows.Count - 1; i >= 0; i--) { XmlElement parentNode = xmlDoc.CreateElement(Element); parentNode.SetAttribute("ID", "" + dset.Tables[0].Rows[i][Element + "ID"]); xmlDoc.DocumentElement.PrependChild(parentNode); for (int j = 0; j < arrPrameter.Count; j++) { XmlElement Xmlobj = xmlDoc.CreateElement(arrPrameter[j].ToString()); XmlText XmlobjText = xmlDoc.CreateTextNode("" + dset.Tables[0].Rows[i][arrPrameter[j].ToString()]); parentNode.AppendChild(Xmlobj); Xmlobj.AppendChild(XmlobjText); } xmlDoc.Save(Server.MapPath("../../Xml/" + foder + "/" + fileName + ".xml")); } }
/// <summary> Writes the current input bindings to a file on disk. </summary> public static void Store() { XmlDocument bindings = new XmlDocument(); XmlNode node; XmlElement element, child; XmlElement root = bindings.CreateElement("Controls"); bindings.InsertAfter(root, bindings.DocumentElement); for (int p = 0; p < 7; p++) { element = bindings.CreateElement("Player" + p); for (int i = 0; i < System.Enum.GetNames(typeof(UserInput)).Length; i++) { child = bindings.CreateElement("Keyboard_" + System.Enum.GetNames(typeof(UserInput))[i]); node = bindings.CreateTextNode("Keyboard_" + System.Enum.GetNames(typeof(UserInput))[i]); node.Value = keyboard[i, p].ToString(); child.AppendChild(node); element.AppendChild(child); } for (int i = 0; i < System.Enum.GetNames(typeof(UserInput)).Length; i++) { child = bindings.CreateElement("Gamepad_" + System.Enum.GetNames(typeof(UserInput))[i]); node = bindings.CreateTextNode("Gamepad_" + System.Enum.GetNames(typeof(UserInput))[i]); node.Value = gamepad[i, p]; element.AppendChild(node); child.AppendChild(node); element.AppendChild(child); } root.AppendChild(element); } bindings.Save(filename); }
///<summary>Returns true if user performed a print job on the CCD. Cannot be moved to OpenDentBusiness/Misc/EhrCCD.cs, because this function uses windows UI components. ///Pass in a valid patient if the CCD is being displayed to reconcile (incoporate into patient record) medications and/or problems and/or allergies. ///patCur can be null, or patCur.PatNum can be 0, to hide the three reconcile buttons. ///strXmlCCD is the actual text of the CCD. ///strAlterateFilPathXslCCD is a full file path to an alternative style sheet. ///This file will only be used in the case where the EHR dll version of the stylesheet couldn not be loaded. ///If neither method works for attaining the stylesheet then an excption will be thrown.</summary> public static bool DisplayCCD(string strXmlCCD,Patient patCur,string strAlterateFilPathXslCCD) { //string xmltext=GetSampleMissingStylesheet(); XmlDocument doc=new XmlDocument(); try { doc.LoadXml(strXmlCCD); } catch { throw new XmlException("Invalid XML"); } string xmlFileName=""; string xslFileName=""; string xslContents=""; if(doc.DocumentElement.Name.ToLower()=="clinicaldocument") {//CCD, CCDA, and C32. xmlFileName="ccd.xml"; xslFileName="ccd.xsl"; xslContents=FormEHR.GetEhrResource("CCD"); if(xslContents=="") { //XSL load from EHR dll failed so see if caller provided an alternative if(strAlterateFilPathXslCCD!="") { //alternative XSL file was provided so use that for our stylesheet xslContents=File.ReadAllText(strAlterateFilPathXslCCD); } } if(xslContents=="") { //one last check to see if we succeeded in finding a stylesheet throw new Exception("No stylesheet found"); } } else if(doc.DocumentElement.Name.ToLower()=="continuityofcarerecord" || doc.DocumentElement.Name.ToLower()=="ccr:continuityofcarerecord") {//CCR xmlFileName="ccr.xml"; xslFileName="ccr.xsl"; xslContents=FormEHR.GetEhrResource("CCR"); } else { MessageBox.Show("This is not a valid CCD, CCDA, CCR, or C32 message. Only the raw text will be shown"); MessageBox.Show(strXmlCCD); return false; } XmlNode node=doc.SelectSingleNode("/processing-instruction(\"xml-stylesheet\")"); if(node==null) {//document does not contain any stylesheet instruction, so add one XmlProcessingInstruction pi=doc.CreateProcessingInstruction("xml-stylesheet","type=\"text/xsl\" href=\""+xslFileName+"\""); doc.InsertAfter(pi,doc.ChildNodes[0]); } else {//alter the existing instruction XmlProcessingInstruction pi=(XmlProcessingInstruction)node; pi.Value="type=\"text/xsl\" href=\""+xslFileName+"\""; } File.WriteAllText(Path.Combine(PrefL.GetTempFolderPath(),xmlFileName),doc.InnerXml.ToString()); File.WriteAllText(Path.Combine(PrefL.GetTempFolderPath(),xslFileName),xslContents); FormEhrSummaryCcdEdit formESCD=new FormEhrSummaryCcdEdit(ODFileUtils.CombinePaths(PrefL.GetTempFolderPath(),xmlFileName),patCur); formESCD.ShowDialog(); string[] arrayFileNames={"ccd.xml","ccd.xsl","ccr.xml","ccr.xsl"}; for(int i=0;i<arrayFileNames.Length;i++) { try { File.Delete(ODFileUtils.CombinePaths(PrefL.GetTempFolderPath(),arrayFileNames[i])); } catch { //Do nothing because the file could have been in use or there were not sufficient permissions. //This file will most likely get deleted next time a file is created. } } return formESCD.DidPrint; }
public void SaveToFile(Stream file, string path) { XmlDocument dataDoc = new XmlDocument(); var rootNode = dataDoc.CreateElement("Points"); foreach(var point in _pointList) { var pointNode = dataDoc.CreateElement("Point"); var attImgX = dataDoc.CreateAttribute("imgx"); attImgX.Value = point.Cam1Img.X.ToString(); var attImgY = dataDoc.CreateAttribute("imgy"); attImgY.Value = point.Cam1Img.Y.ToString(); var attRealX = dataDoc.CreateAttribute("realx"); attRealX.Value = point.Real.X.ToString(); var attRealY = dataDoc.CreateAttribute("realy"); attRealY.Value = point.Real.Y.ToString(); var attRealZ = dataDoc.CreateAttribute("realz"); attRealZ.Value = point.Real.Z.ToString(); pointNode.Attributes.Append(attImgX); pointNode.Attributes.Append(attImgY); pointNode.Attributes.Append(attRealX); pointNode.Attributes.Append(attRealY); pointNode.Attributes.Append(attRealZ); rootNode.AppendChild(pointNode); } dataDoc.InsertAfter(rootNode, dataDoc.DocumentElement); dataDoc.Save(file); }
public void SaveToFile(Stream file, string path) { XmlDocument dataDoc = new XmlDocument(); var rootNode = dataDoc.CreateElement("Grids"); foreach (var grid in _gridsList) { //var gridNode = dataDoc.CreateElement("Grid"); //var gridAttNum = dataDoc.CreateAttribute("num"); //gridAttNum.Value = grid.Num.ToString(); //var gridAttLabel = dataDoc.CreateAttribute("label"); //gridAttLabel.Value = grid.Label; //gridNode.Attributes.Append(gridAttNum); //gridNode.Attributes.Append(gridAttLabel); //var gridWidth = dataDoc.CreateElement("Width"); //var widthAttX = dataDoc.CreateAttribute("X"); //widthAttX.Value = grid.WidthX.ToString(); //var widthAttY = dataDoc.CreateAttribute("Y"); //widthAttY.Value = grid.WidthY.ToString(); //var widthAttZ = dataDoc.CreateAttribute("Z"); //widthAttZ.Value = grid.WidthZ.ToString(); //gridWidth.Attributes.Append(widthAttX); //gridWidth.Attributes.Append(widthAttY); //gridWidth.Attributes.Append(widthAttZ); //gridNode.AppendChild(gridWidth); //var gridHeight = dataDoc.CreateElement("Height"); //var heightAttX = dataDoc.CreateAttribute("X"); //heightAttX.Value = grid.HeightX.ToString(); //var heightAttY = dataDoc.CreateAttribute("Y"); //heightAttY.Value = grid.HeightY.ToString(); //var heightAttZ = dataDoc.CreateAttribute("Z"); //heightAttZ.Value = grid.HeightZ.ToString(); //gridHeight.Attributes.Append(heightAttX); //gridHeight.Attributes.Append(heightAttY); //gridHeight.Attributes.Append(heightAttZ); //gridNode.AppendChild(gridHeight); //var gridZero = dataDoc.CreateElement("Zero"); //var zeroAttX = dataDoc.CreateAttribute("X"); //zeroAttX.Value = grid.ZeroX.ToString(); //var zeroAttY = dataDoc.CreateAttribute("Y"); //zeroAttY.Value = grid.ZeroY.ToString(); //var zeroAttZ = dataDoc.CreateAttribute("Z"); //zeroAttZ.Value = grid.ZeroZ.ToString(); //gridZero.Attributes.Append(zeroAttX); //gridZero.Attributes.Append(zeroAttY); //gridZero.Attributes.Append(zeroAttZ); //gridNode.AppendChild(gridZero); //rootNode.AppendChild(gridNode); } dataDoc.InsertAfter(rootNode, dataDoc.DocumentElement); dataDoc.Save(file); }
/// <summary> /// This method will save the collection to the file specified /// </summary> /// <param name="fileName">File that will contain the data</param> /// <returns>True if successful</returns> public bool Save( string fileName, string encoding ) { bool res = false; if (fileName == null || encoding == null) { throw ( new ArgumentException( Workshare.Reports.Properties.Resources.CANNOTSAVE ) ); } // Check that the file can be saved to if (CheckFile( fileName )) { XmlDocument xmlDoc = new XmlDocument(); try { XmlDeclaration xmlDec = xmlDoc.CreateXmlDeclaration( "1.0", encoding, "no" ); StringBuilder cmt = new StringBuilder(); cmt.AppendFormat( Workshare.Reports.Properties.Resources.COMMENT1, DateTime.Now.ToLongDateString(), DateTime.Now.ToLongTimeString() ); XmlComment xmlCmt1 = xmlDoc.CreateComment( cmt.ToString() ); XmlNode xmlRoot = xmlDoc.ImportNode( Node, true ); XmlSchemaSet xss = new XmlSchemaSet(); StringBuilder xsd = new StringBuilder(); xsd.AppendFormat("{0}{1}{2}", AppDomain.CurrentDomain.BaseDirectory, (AppDomain.CurrentDomain.BaseDirectory.EndsWith("\\") ? "" : "\\"), "TraceScan.xsd"); xss.Add("urn:www.workshare.com/trace/1.0", xsd.ToString()); xmlDoc.Schemas.Add(xss); xmlDoc.InsertBefore( xmlDec, xmlDoc.DocumentElement ); xmlDoc.InsertAfter( xmlCmt1, xmlDec ); xmlDoc.InsertAfter( xmlRoot, xmlCmt1 ); xmlDoc.Save( fileName ); m_scanSaved = true; res = true; } catch (XmlException e) { StringBuilder sb = new StringBuilder(); sb.AppendFormat( Workshare.Reports.Properties.Resources.XMLERROR, Environment.NewLine, e.Message ); throw ( new InvalidOperationException( sb.ToString() ) ); } } return res; }
public void SaveToFile(Stream file, string path) { XmlDocument xmlDoc = new XmlDocument(); var camerasNode = xmlDoc.CreateElement("Cameras"); var cam1Node = xmlDoc.CreateElement("Camera"); var cam1AttNum = xmlDoc.CreateAttribute("num"); cam1AttNum.Value = "1"; var cam1AttCalib = xmlDoc.CreateAttribute("is_calibrated"); cam1AttCalib.Value = IsCamLeftCalibrated.ToString(); cam1Node.Attributes.Append(cam1AttNum); cam1Node.Attributes.Append(cam1AttCalib); if(IsCamLeftCalibrated) { cam1Node.AppendChild(XmlExtensions.CreateMatrixNode(xmlDoc, _camLeft)); if(_distortionModelLeft != null) { cam1Node.AppendChild(XmlExtensions.CreateDistortionModelNode(xmlDoc, _distortionModelLeft)); } } camerasNode.AppendChild(cam1Node); var cam2Node = xmlDoc.CreateElement("Camera"); var cam2AttNum = xmlDoc.CreateAttribute("num"); cam2AttNum.Value = "2"; var cam2AttCalib = xmlDoc.CreateAttribute("is_calibrated"); cam2AttCalib.Value = IsCamRightCalibrated.ToString(); cam2Node.Attributes.Append(cam2AttNum); cam2Node.Attributes.Append(cam2AttCalib); if(IsCamRightCalibrated) { cam2Node.AppendChild(XmlExtensions.CreateMatrixNode(xmlDoc, _camRight)); if(_distortionModelRight != null) { cam2Node.AppendChild(XmlExtensions.CreateDistortionModelNode(xmlDoc, _distortionModelRight)); } } camerasNode.AppendChild(cam2Node); xmlDoc.InsertAfter(camerasNode, xmlDoc.DocumentElement); xmlDoc.Save(file); }
public void SaveToFile(Stream file, string path) { XmlDocument dataDoc = new XmlDocument(); var rootNode = dataDoc.CreateElement("Grids"); foreach (var grid in _gridsList) { var gridNode = dataDoc.CreateElement("Grid"); var gridAttNum = dataDoc.CreateAttribute("num"); gridAttNum.Value = grid.Num.ToString(); var gridAttLabel = dataDoc.CreateAttribute("label"); gridAttLabel.Value = grid.Label; gridNode.Attributes.Append(gridAttNum); gridNode.Attributes.Append(gridAttLabel); gridNode.AppendChild(grid.TopLeft.CreateXmlNode(dataDoc, "TopLeft")); gridNode.AppendChild(grid.TopRight.CreateXmlNode(dataDoc, "TopRight")); gridNode.AppendChild(grid.BotLeft.CreateXmlNode(dataDoc, "BotLeft")); gridNode.AppendChild(grid.BotRight.CreateXmlNode(dataDoc, "BotRight")); XmlNode rowsNode = dataDoc.CreateElement("Rows"); var rowsAtt = dataDoc.CreateAttribute("count"); rowsAtt.Value = grid.Rows.ToString(); rowsNode.Attributes.Append(rowsAtt); gridNode.AppendChild(rowsNode); XmlNode colsNode = dataDoc.CreateElement("Columns"); var colsAtt = dataDoc.CreateAttribute("count"); colsAtt.Value = grid.Columns.ToString(); colsNode.Attributes.Append(colsAtt); gridNode.AppendChild(colsNode); rootNode.AppendChild(gridNode); } dataDoc.InsertAfter(rootNode, dataDoc.DocumentElement); dataDoc.Save(file); }
public void SaveToFile(Stream file, string path) { XmlDocument dataDoc = new XmlDocument(); var rootNode = dataDoc.CreateElement("Lines"); foreach(var line in _linesList) { var lineNode = dataDoc.CreateElement("Line"); foreach(var point in line) { var pointNode = dataDoc.CreateElement("Point"); var attImgX = dataDoc.CreateAttribute("x"); attImgX.Value = point.X.ToString("F3"); var attImgY = dataDoc.CreateAttribute("y"); attImgY.Value = point.Y.ToString("F3"); pointNode.Attributes.Append(attImgX); pointNode.Attributes.Append(attImgY); lineNode.AppendChild(pointNode); } rootNode.AppendChild(lineNode); } dataDoc.InsertAfter(rootNode, dataDoc.DocumentElement); dataDoc.Save(file); }