コード例 #1
0
ファイル: XmlHelper.cs プロジェクト: TeddyAlbina/cs2gen
        public void AddComment(string xpath, System.Xml.XmlComment oXmlComment)
        {
            System.Xml.XmlNode Parent = XmlDocument.SelectSingleNode(xpath);
            int nI = 0;

            System.Xml.XmlNode selected = null;
            foreach (System.Xml.XmlNode oXmlNode in Parent.ChildNodes)
            {
                if (oXmlNode.NodeType == System.Xml.XmlNodeType.Element || oXmlNode.NodeType == System.Xml.XmlNodeType.Attribute)
                {
                    if (nI == 0)
                    {
                        selected = oXmlNode;
                        nI      += 1;
                    }
                }
            }
            if (nI > 0)
            {
                Parent.InsertBefore(oXmlComment, selected);
            }
            else
            {
                Parent.AppendChild(oXmlComment);
            }
            //System.Xml.XmlNode oXmlNode = XmlDocument.SelectSingleNode(xpath);
            //oXmlNode.AppendChild(oXmlComment);
        }
コード例 #2
0
ファイル: XmlHelper.cs プロジェクト: TeddyAlbina/cs2gen
        public void AddComment(System.Xml.XmlNode Parent, System.Xml.XmlComment oXmlComment)
        {
            int nI = 0;

            System.Xml.XmlNode selected = null;
            foreach (System.Xml.XmlNode oXmlNode in Parent.ChildNodes)
            {
                if (oXmlNode.NodeType == System.Xml.XmlNodeType.Element || oXmlNode.NodeType == System.Xml.XmlNodeType.Attribute)
                {
                    if (nI == 0)
                    {
                        selected = oXmlNode;
                        nI      += 1;
                    }
                }
            }
            if (nI > 0)
            {
                Parent.InsertBefore(oXmlComment, selected);
            }
            else
            {
                Parent.AppendChild(oXmlComment);
            }
        }
コード例 #3
0
 /// <summary>
 /// 将指定的菜单项提升一个位置。
 /// </summary>
 /// <param name="ID">菜单项 ID。</param>
 public void SendMenuItemToPre(string ID)
 {
     System.Xml.XmlNodeList xnl = this.xmlDocument.SelectNodes("/Menu/MenuGroup/MenuItem");
     foreach (System.Xml.XmlNode tmp in xnl)
     {
         if (tmp.Attributes["ID"] != null && tmp.Attributes["ID"].Value == ID)
         {
             System.Xml.XmlNode ParentNode      = tmp.ParentNode;
             System.Xml.XmlNode PreviousSibling = tmp.PreviousSibling;
             if (ParentNode != null && PreviousSibling != null)
             {
                 ParentNode.RemoveChild(tmp);
                 ParentNode.InsertBefore(tmp, PreviousSibling);
                 return;
             }
         }
     }
 }
コード例 #4
0
        System.Xml.XmlNode GetProviderNode(string rootAddress, System.Xml.XmlNode serviceNode)
        {
            System.Xml.XmlNode provider = null;
            if (serviceNode.HasChildNodes)
            {
                serviceNode.RemoveAll();
                //foreach (System.Xml.XmlNode item in serviceNode.ChildNodes)
                //{

                //foreach (System.Xml.XmlNode node in item.ChildNodes)
                //{
                //    if (node.Name != "RootAddress") continue;
                //    var tmp = Convert.ToString(node.InnerText);
                //    if (!tmp.StartsWith(this.RootAddress, StringComparison.InvariantCultureIgnoreCase) || string.IsNullOrEmpty(tmp))
                //        continue;
                //    provider = item;
                //    break;
                //}
                //if (provider != null)
                //    break;
                //}
            }
            if (provider == null)
            {
                provider = serviceNode.OwnerDocument.CreateElement("ServiceProvider", serviceNode.OwnerDocument.DocumentElement.NamespaceURI);

                var node = provider.OwnerDocument.CreateElement("RootAddress", serviceNode.OwnerDocument.DocumentElement.NamespaceURI);
                provider.AppendChild(node);
                node = provider.OwnerDocument.CreateElement("DataServiceAddress", serviceNode.OwnerDocument.DocumentElement.NamespaceURI);
                provider.AppendChild(node);
                node = provider.OwnerDocument.CreateElement("ApplicationPackageAddress", serviceNode.OwnerDocument.DocumentElement.NamespaceURI);
                provider.AppendChild(node);

                if (serviceNode.HasChildNodes)
                {
                    serviceNode.InsertBefore(provider, serviceNode.FirstChild);
                }
                else
                {
                    serviceNode.AppendChild(provider);
                }
            }
            return(provider);
        }
コード例 #5
0
        /// <summary>
        /// Inserts the specified XML node at the specified position
        /// </summary>
        internal static bool InsertXmlNode(XmlCursorPos cursorPos, System.Xml.XmlNode node, XmlRules xmlRules, bool setNewCursorPosBehindNewInsertedNode)
        {
            System.Xml.XmlNode parentNode = cursorPos.ActualNode.ParentNode;

            switch (cursorPos.PosOnNode)
            {
            case XmlCursorPositions.CursorOnNodeStartTag:     // replace the acual node
            case XmlCursorPositions.CursorOnNodeEndTag:
                parentNode.ReplaceChild(node, cursorPos.ActualNode);
                break;

            case XmlCursorPositions.CursorInFrontOfNode:     // insert before actual node
                parentNode.InsertBefore(node, cursorPos.ActualNode);
                break;

            case XmlCursorPositions.CursorBehindTheNode:     // insert after actual node
                parentNode.InsertAfter(node, cursorPos.ActualNode);
                break;

            case XmlCursorPositions.CursorInsideTheEmptyNode:     // insert into empty node
                cursorPos.ActualNode.AppendChild(node);
                break;

            case XmlCursorPositions.CursorInsideTextNode:     // insert into textnode

                // Make the text available as a node before the insertion position
                string             textDavor     = cursorPos.ActualNode.InnerText.Substring(0, cursorPos.PosInTextNode);
                System.Xml.XmlNode textDavorNode = parentNode.OwnerDocument.CreateTextNode(textDavor);

                // Provide the text behind the insert position as a node
                string             textAfter     = cursorPos.ActualNode.InnerText.Substring(cursorPos.PosInTextNode, cursorPos.ActualNode.InnerText.Length - cursorPos.PosInTextNode);
                System.Xml.XmlNode textAfterNode = parentNode.OwnerDocument.CreateTextNode(textAfter);

                // Insert the node to be inserted between the new before and after text node
                // -> so replace the old text node with
                // textbefore - newNode - textafter
                parentNode.ReplaceChild(textDavorNode, cursorPos.ActualNode);
                parentNode.InsertAfter(node, textDavorNode);
                parentNode.InsertAfter(textAfterNode, node);
                break;

            default:
                throw new ApplicationException(String.Format("InsertXmlNode: unknown PosOnNode {0}", cursorPos.PosOnNode));
            }

            // set cursor
            if (setNewCursorPosBehindNewInsertedNode)
            {
                // Place cursor behind the new node
                cursorPos.SetPos(node, XmlCursorPositions.CursorBehindTheNode);
            }
            else
            {
                if (xmlRules.HasEndTag(node))
                {
                    // Place cursor in the new node
                    cursorPos.SetPos(node, XmlCursorPositions.CursorInsideTheEmptyNode);
                }
                else
                {
                    // Place cursor behind the new node
                    cursorPos.SetPos(node, XmlCursorPositions.CursorBehindTheNode);
                }
            }
            return(true);
        }