Add child node to xml document

This sample shows how to build an XML node and add it as a new child in an existing

        /// <summary>
        /// This routine is needed when an in-bound endpoint Sends TMXML with no Itinerary Node in the Header
        /// The Receiver must make sure that the Itinerary node is present in the Header.
        /// </summary>
        /// <returns></returns>
        public static XmlDocument AddItineraryNode(XmlDocument xmlDoc)
            xmlDoc.PreserveWhitespace = true; //making sure no whitespaces get added
            string strXPath = "//*[local-name()='ItineraryStep']";
            string strItinerary =
                    "<policyName>NULL</policyName>" +
                     "<status>NULL</status>" +
                     "<currentStepName>NULL</currentStepName>" +
                     "<currentStepStatus>NULL</currentStepStatus>" +
                     "<currentStepIndex>0</currentStepIndex>" +
                     "<currentStepErrorType>NULL</currentStepErrorType>" +
                     "<currentProcessCode>NULL</currentProcessCode>" +
                     "<currentProcessMethod>NULL</currentProcessMethod>" +
            XmlNamespaceManager iMgr = new XmlNamespaceManager(xmlDoc.NameTable);
            XmlNode nodeItin = xmlDoc.SelectSingleNode(strXPath, iMgr);

            if (nodeItin == null)
                XmlElement newItinerary = xmlDoc.CreateElement("Itinerary");
                newItinerary.InnerXml = strItinerary;

            return xmlDoc;




Leave a Reply