コード例 #1
0
 System.Xml.XmlElement GetServiceElement(string name, System.Xml.XmlNode serviceNode, System.Xml.XmlNode orderNode = null)
 {
     System.Xml.XmlNode node = null;
     foreach (System.Xml.XmlNode item in serviceNode.ChildNodes)
     {
         if (item.Name != name)
         {
             continue;
         }
         node = item;
         break;
     }
     if (node == null)
     {
         node = serviceNode.OwnerDocument.CreateElement(name, serviceNode.OwnerDocument.DocumentElement.NamespaceURI);
         if (orderNode == null)
         {
             serviceNode.AppendChild(node);
         }
         else
         {
             serviceNode.InsertAfter(node, orderNode);
         }
     }
     return((System.Xml.XmlElement)node);
 }
コード例 #2
0
 /// <summary>
 /// 将指定的菜单项下降一个位置。
 /// </summary>
 /// <param name="ID">菜单项 ID。</param>
 public void SendMenuItemToBack(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 NextSibling = tmp.NextSibling;
             if (NextSibling != null && NextSibling != null)
             {
                 ParentNode.RemoveChild(tmp);
                 ParentNode.InsertAfter(tmp, NextSibling);
                 return;
             }
         }
     }
 }
コード例 #3
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);
        }