Build and return a default XML doc from C#

This code builds an xml document in memory, then returns it as an System.Xml.XmlDocument. It also show the proper way to build an XML date.

        /// <summary>
        /// This routine is needed when an in-bound endpoint has a map failure when translating
        /// inbound schema to  TMXML. 
        /// </summary>
        /// <returns></returns>
        public static XmlDocument ReturnNewTMXML()
            DateTime currentDateTime = DateTime.Now;
            string strDateTime = currentDateTime.ToLongDateString();

            string strMyDoc =
            "<n2:MyRootEl xsi:schemaLocation='http://MyNamespace.MySchema.xsd' +
'xmlns:xsi=''>" +
                "<source>" +
                  "<objectId>NULL</objectId>" +
                  "<objectType>NULL</objectType>" +
                  "<requestor>NULL</requestor>" +
                  "<transactionGuid>NULL</transactionGuid>" +
                  "<requestType>NULL</requestType>" +
                  "<dateTimeReceived>" + TFBIC.Common.BizTalk.Components.MapHelper.ConvertDateTimetoXmlDateTime(strDateTime) + "</dateTimeReceived>" +
                  "<isResponseExpected>false</isResponseExpected>" +
                "</source>" +

            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.PreserveWhitespace = true; //making sure no whitespaces get added
            return xmlDoc;




Leave a Reply