Esempio n. 1
0
        /// <summary>
        /// Adds the specified XPATH.
        /// </summary>
        /// <param name="mod">The mod.</param>
        private void Add(XmlAdd mod)
        {
            try
            {
                XmlNodeList nodes = ReturnMatchingNodes(mod.xpath);

                if (nodes.Count > 0)
                {
                    foreach (XmlNode node in nodes)
                    {
                        if (mod.attribute != null)
                        {
                            XmlAttribute a = document.CreateAttribute(mod.attribute);
                            a.Value = mod.Value;
                            node.Attributes.Append(a);
                        }
                        else
                        {
                            //See if we have a namespace in a parent...
                            //XmlNode tableNode = GetFirstParentNodeWithNamespaceUri(node);

                            XmlDocumentFragment frag = document.CreateDocumentFragment();
                            frag.InnerXml = mod.Value;

                            XmlNode imported = document.ImportNode(frag, true);
                            node.AppendChild(imported);

                            //TODO This does not work as yet....may need 3.0 and XDocument, as this stuff sucks.....
                            //if (tableNode != null)
                            //{
                            //    XmlNode test = document.CreateNode(XmlNodeType.DocumentFragment, "xmlns", imported.Name, tableNode.NamespaceURI);
                            //    test.InnerXml = imported.InnerXml;
                            //    node.AppendChild(test);
                            //}
                            //else
                            //{
                            //    node.AppendChild(imported);
                            //}
                        }
                    }
                }
            }
            catch (Exception i)
            {
                LogFailureAndOptionallyThrow(mod.xpath, "update", i);
            }
        }
        /// <summary>
        /// Adds the specified XPATH.
        /// </summary>
        /// <param name="mod">The mod.</param>
        private void Add(XmlAdd mod)
        {
            try
            {
                XmlNodeList nodes = ReturnMatchingNodes(mod.xpath);

                if (nodes.Count > 0)
                {
                    foreach (XmlNode node in nodes)
                    {
                        if (mod.attribute != null)
                        {
                            XmlAttribute a = document.CreateAttribute(mod.attribute);
                            a.Value = mod.Value;
                            node.Attributes.Append(a);
                        }
                        else
                        {
                            //See if we have a namespace in a parent...
                            //XmlNode tableNode = GetFirstParentNodeWithNamespaceUri(node);

                            XmlDocumentFragment frag = document.CreateDocumentFragment();
                            frag.InnerXml = mod.Value;
                            
                            XmlNode imported = document.ImportNode(frag, true);
                            node.AppendChild(imported);

                            //TODO This does not work as yet....may need 3.0 and XDocument, as this stuff sucks.....
                            //if (tableNode != null)
                            //{
                            //    XmlNode test = document.CreateNode(XmlNodeType.DocumentFragment, "xmlns", imported.Name, tableNode.NamespaceURI);
                            //    test.InnerXml = imported.InnerXml;
                            //    node.AppendChild(test);
                            //}
                            //else
                            //{
                            //    node.AppendChild(imported);
                            //}
                        }
                    }
                }
            }
            catch (Exception i)
            {
                LogFailureAndOptionallyThrow(mod.xpath, "update", i);
            }
        }