Wednesday, January 4

Creating an xml debugging file on the fly within development code

I sometimes use this technique for debugging during dev stages. Make sure you give the correct access to the folder in which you would like the xml file created

XmlTextWriter textWriter = new XmlTextWriter(@"C:\Testpipeline\myXmFile.xml", null);
                textWriter.WriteStartDocument();
                textWriter.WriteStartElement("Context");

                for (int i = 0; i < pInMsg.Context.CountProperties; i++)
                {
                    uvalue = pInMsg.Context.ReadAt(i, out sname, out snamespace).ToString();

                    //write all to new context except messagetype
                    if (sname != "MessageType")
                    {
                        outMsg.Context.Write(sname, snamespace, uvalue);

                        textWriter.WriteStartElement(sname, snamespace);
                        textWriter.WriteString(uvalue);
                        textWriter.WriteEndElement();

                    }
                    //promote all promoted
                    if (pInMsg.Context.IsPromoted(sname, snamespace))
                    {
                      
outMsg.Context.Promote(sname, snamespace, nvalue);                    }                   
                }


                textWriter.WriteEndElement();
                textWriter.WriteEndDocument();
                textWriter.Close();

No comments:

Post a Comment