Esempio n. 1
0
        /// <summary>
        /// Replace xml node in NBrightInfo structure
        /// </summary>
        /// <param name="strXml">New XML, must be in NBright Strucutre (genxml/...)</param>
        /// <param name="xPathSource">Source path of the xml, this is for the new node and the old existing node</param>
        /// <param name="xPathRootDestination">parent node to place the new node onto</param>
        /// <param name="addNode">add if the node doesn;t already exists.</param>
        public void ReplaceXmlNode(string strXml, string xPathSource, string xPathRootDestination, bool addNode = true)
        {
            var xmlDocNew = new XmlDocument();

            xmlDocNew.LoadXml(strXml);

            var xmlNod = XMLDoc.SelectSingleNode(xPathSource);

            if (xmlNod != null)
            {
                var xmlNod2 = xmlDocNew.SelectSingleNode(xPathSource);
                if (xmlNod2 != null)
                {
                    var newNod           = XMLDoc.ImportNode(xmlNod2, true);
                    var selectSingleNode = XMLDoc.SelectSingleNode(xPathRootDestination);
                    if (selectSingleNode != null)
                    {
                        selectSingleNode.ReplaceChild(newNod, xmlNod);
                        XMLData = XMLDoc.OuterXml;
                    }
                }
            }
            else
            {
                if (addNode)
                {
                    AddXmlNode(strXml, xPathSource, xPathRootDestination);
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Add a XML node to a parent destination
        /// </summary>
        /// <param name="strXml">source XML</param>
        /// <param name="xPathSource">source xpath</param>
        /// <param name="xPathRootDestination">parent xpath in destination</param>
        public void AddXmlNode(string strXml, string xPathSource, string xPathRootDestination)
        {
            var xmlDocNew = new XmlDocument();

            xmlDocNew.LoadXml(strXml);

            var xmlTarget = XMLDoc.SelectSingleNode(xPathRootDestination);

            if (xmlTarget != null)
            {
                var xmlNod2 = xmlDocNew.SelectSingleNode(xPathSource);
                if (xmlNod2 != null)
                {
                    var newNod = XMLDoc.ImportNode(xmlNod2, true);
                    xmlTarget.AppendChild(newNod);
                    XMLData = XMLDoc.OuterXml;
                }
            }
        }