Exemple #1
0
        /// <summary>
        /// 已重载:向XML节点保存文本格式信息和字符数据
        /// </summary>
        /// <param name="myElement"></param>
        /// <returns></returns>
        public override bool ToXML(System.Xml.XmlElement myElement)
        {
            if (myElement == null)
            {
                return(false);
            }
            switch (myOwnerDocument.Info.SaveMode)
            {
            case 0:     // 保存所有数据
                System.Xml.XmlText myText = myElement.OwnerDocument.CreateTextNode(myChar.ToString());
                myElement.AppendChild(myText);
                //base.BaseToXML( myElement );
                myAttributes.ToXML(myElement);
                break;

            case 1:     // 保存纯文本数据
                System.Xml.XmlText myText2 = myElement.OwnerDocument.CreateTextNode(myChar.ToString());
                myElement.AppendChild(myText2);
                return(true);

            //break;
            case 2:     // 只保存结构化数据
                break;

            default:
                return(false);
            }
            return(true);
        }
        /// <summary>
        /// Inserts a text between two nodes
        /// </summary>
        internal static void InsertTextBetweenTwoNodes(XmlCursorPos cursorPos, System.Xml.XmlNode nodeBefore, System.Xml.XmlNode nodeAfter, string text, XmlRules xmlRules)
        {
            if (ToolboxXml.IsTextOrCommentNode(nodeBefore))  // if the node is already text before, then simply append to it
            {
                nodeBefore.InnerText += text;
                cursorPos.SetPos(nodeBefore, XmlCursorPositions.CursorInsideTextNode, nodeBefore.InnerText.Length);
            }
            else  // the node before is no text
            {
                if (ToolboxXml.IsTextOrCommentNode(nodeAfter))  // if the node behind it is already text then just paste it into
                {
                    nodeAfter.InnerText = $"{text}{nodeAfter.InnerText}";
                    cursorPos.SetPos(nodeAfter, XmlCursorPositions.CursorInsideTextNode, text.Length);
                }
                else // the node behind is also no text
                {
                    // Insert between two non-text nodes
                    if (xmlRules.IsThisTagAllowedAtThisPos("#PCDATA", cursorPos))
                    {
                        System.Xml.XmlText newTextNode = cursorPos.ActualNode.OwnerDocument.CreateTextNode(text);
                        InsertXmlNode(cursorPos, newTextNode, xmlRules, false);
                    }
                    else
                    {
#warning Insert another correct message or sound
                        Debug.Assert(false, "Error - Beep!");
                    }
                }
            }
        }
Exemple #3
0
 public System.Xml.XmlElement CreateElement(string Name, string Value)
 {
     System.Xml.XmlElement oXmlElement = XmlDocument.CreateElement(Name);
     System.Xml.XmlText    oXmlText    = XmlDocument.CreateTextNode(Value);
     oXmlElement.AppendChild(oXmlText);
     return(oXmlElement);
 }
        Stream(System.Xml.XmlCharacterData charData)
        {
            m_dataObjs.Add(new Snoop.Data.ClassSeparator(typeof(System.Xml.XmlCharacterData)));

            m_dataObjs.Add(new Snoop.Data.Int("Length", charData.Length));
            m_dataObjs.Add(new Snoop.Data.String("Data", charData.Data));

            System.Xml.XmlCDataSection cDataSection = charData as System.Xml.XmlCDataSection;
            if (cDataSection != null)
            {
                Stream(cDataSection);
                return;
            }

            System.Xml.XmlComment comment = charData as System.Xml.XmlComment;
            if (comment != null)
            {
                Stream(comment);
                return;
            }

            System.Xml.XmlSignificantWhitespace swSpace = charData as System.Xml.XmlSignificantWhitespace;
            if (swSpace != null)
            {
                Stream(swSpace);
                return;
            }

            System.Xml.XmlText txt = charData as System.Xml.XmlText;
            if (txt != null)
            {
                Stream(txt);
                return;
            }

            System.Xml.XmlWhitespace wSpace = charData as System.Xml.XmlWhitespace;
            if (wSpace != null)
            {
                Stream(wSpace);
                return;
            }
        }
Exemple #5
0
        public static bool _CreateTextNode_System_Configuration_ConfigXmlDocument_System_String( )
        {
            //Parameters
            System.String text = null;

            //ReturnType/Value
            System.Xml.XmlText returnVal_Real        = null;
            System.Xml.XmlText returnVal_Intercepted = null;

            //Exception
            Exception exception_Real        = null;
            Exception exception_Intercepted = null;

            InterceptionMaintenance.disableInterception( );

            try
            {
                returnValue_Real = System.Configuration.ConfigXmlDocument.CreateTextNode(text);
            }

            catch (Exception e)
            {
                exception_Real = e;
            }


            InterceptionMaintenance.enableInterception( );

            try
            {
                returnValue_Intercepted = System.Configuration.ConfigXmlDocument.CreateTextNode(text);
            }

            catch (Exception e)
            {
                exception_Intercepted = e;
            }


            Return((exception_Real.Messsage == exception_Intercepted.Message) && (returnValue_Real == returnValue_Intercepted));
        }
Exemple #6
0
        public static bool _SplitText_System_Xml_XmlText_System_Int32( )
        {
            //Parameters
            System.Int32 offset = null;

            //ReturnType/Value
            System.Xml.XmlText returnVal_Real        = null;
            System.Xml.XmlText returnVal_Intercepted = null;

            //Exception
            Exception exception_Real        = null;
            Exception exception_Intercepted = null;

            InterceptionMaintenance.disableInterception( );

            try
            {
                returnValue_Real = System.Xml.XmlText.SplitText(offset);
            }

            catch (Exception e)
            {
                exception_Real = e;
            }


            InterceptionMaintenance.enableInterception( );

            try
            {
                returnValue_Intercepted = System.Xml.XmlText.SplitText(offset);
            }

            catch (Exception e)
            {
                exception_Intercepted = e;
            }


            Return((exception_Real.Messsage == exception_Intercepted.Message) && (returnValue_Real == returnValue_Intercepted));
        }
Exemple #7
0
        /// <summary>
        /// Encodes a Primitive in XML by adding it's value as a child of the given Element.
        /// Returns true if the given Primitive contains a value.
        /// </summary>
        ///
        /// <exception cref="DataTypeException">    Thrown when a Data Type error condition occurs. </exception>
        ///
        /// <param name="datatypeObject">   The datatype object. </param>
        /// <param name="datatypeElement">  Element describing the datatype. </param>
        ///
        /// <returns>   true if it succeeds, false if it fails. </returns>

        private bool EncodePrimitive(IPrimitive datatypeObject, System.Xml.XmlElement datatypeElement)
        {
            bool hasValue = false;

            if (datatypeObject.Value != null && !datatypeObject.Value.Equals(""))
            {
                hasValue = true;
            }

            System.Xml.XmlText t = datatypeElement.OwnerDocument.CreateTextNode(datatypeObject.Value);
            if (hasValue)
            {
                try
                {
                    datatypeElement.AppendChild(t);
                }
                catch (System.Exception e)
                {
                    throw new DataTypeException("DOMException encoding Primitive: ", e);
                }
            }
            return(hasValue);
        }
Exemple #8
0
        /// <summary> Encodes a Primitive in XML by adding it's value as a child of the given Element.
        /// Returns true if the given Primitive contains a value.
        /// </summary>
        private bool encodePrimitive(Primitive datatypeObject, System.Xml.XmlElement datatypeElement)
        {
            bool hasValue = false;

            if (datatypeObject.Value != null && !datatypeObject.Value.Equals(""))
            {
                hasValue = true;
            }

            System.Xml.XmlText t = datatypeElement.OwnerDocument.CreateTextNode(datatypeObject.Value);
            if (hasValue)
            {
                try
                {
                    datatypeElement.AppendChild(t);
                }
                //UPGRADE_TODO: Class 'org.w3c.dom.DOMException' was converted to 'System.Exceptiont' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073'"
                catch (System.Exception e)
                {
                    throw new DataTypeException("DOMException encoding Primitive: ", e);
                }
            }
            return(hasValue);
        }
        Stream(System.Xml.XmlText text)
        {
            m_dataObjs.Add(new Snoop.Data.ClassSeparator(typeof(System.Xml.XmlText)));

            // no data to display at this level
        }
Exemple #10
0
 internal XmlText(XmlDocument owner, SystemXmlText backingText)
 {
     _owner       = owner;
     _backingText = backingText;
 }
Exemple #11
0
 /// <summary>
 /// 追加对象数据到XML节点
 /// </summary>
 /// <param name="myElement"></param>
 /// <returns></returns>
 public bool AppendToXML(System.Xml.XmlElement myElement)
 {
     System.Xml.XmlText myText = myElement.OwnerDocument.CreateTextNode(myChar.ToString());
     myElement.AppendChild(myText);
     return(true);
 }
        /// <summary>
        /// Inserts the specified text at the current cursor position, if possible
        /// </summary>
        internal static InsertTextResult InsertText(XmlCursorPos cursorPos, string rawText, XmlRules xmlRules)
        {
            // Revise the entered text in preprocessing if necessary.
            // In an AIML 1.1 DTD this can mean, for example, that the text for insertion into the PATTERN tag is changed to upper case
            string text = xmlRules.InsertTextTextPreProcessing(rawText, cursorPos, out System.Xml.XmlNode replacementNode);

            if (replacementNode != null)
            {
                // If the entered text has become a node instead, e.g. with AIML,
                // if you press * in a template and then want to insert a <star> instead
                return(new InsertTextResult {
                    ReplaceNode = replacementNode
                });
            }

            switch (cursorPos.PosOnNode)
            {
            case XmlCursorPositions.CursorOnNodeStartTag:
            case XmlCursorPositions.CursorOnNodeEndTag:
                // First check whether this node may be replaced by a text node
                if (xmlRules.IsThisTagAllowedAtThisPos("#PCDATA", cursorPos))
                {
                    // The selected node by a newly created text node
                    System.Xml.XmlText neuerTextNode = cursorPos.ActualNode.OwnerDocument.CreateTextNode(text);
                    cursorPos.ActualNode.ParentNode.ReplaceChild(cursorPos.ActualNode, neuerTextNode);
                    cursorPos.SetPos(neuerTextNode, XmlCursorPositions.CursorBehindTheNode);
                }
                throw new ApplicationException(String.Format("InsertText: unknown CursorPos {0}", cursorPos.PosOnNode));

            case XmlCursorPositions.CursorBehindTheNode:
                InsertTextBetweenTwoNodes(cursorPos, cursorPos.ActualNode, cursorPos.ActualNode.NextSibling, text, xmlRules);
                break;

            case XmlCursorPositions.CursorInFrontOfNode:
                InsertTextBetweenTwoNodes(cursorPos, cursorPos.ActualNode.PreviousSibling, cursorPos.ActualNode, text, xmlRules);
                break;

            case XmlCursorPositions.CursorInsideTheEmptyNode:
                // First check if text is allowed inside the empty node
                if (xmlRules.IsThisTagAllowedAtThisPos("#PCDATA", cursorPos))
                {
                    // Then create a text node within the empty node with the desired text content
                    System.Xml.XmlText newTextNode = cursorPos.ActualNode.OwnerDocument.CreateTextNode(text);
                    cursorPos.ActualNode.AppendChild(newTextNode);
                    cursorPos.SetPos(newTextNode, XmlCursorPositions.CursorBehindTheNode);
                }
                else
                {
                    // Error BEEEEP!
                }
                break;

            case XmlCursorPositions.CursorInsideTextNode:
                string textBeforeNode  = cursorPos.ActualNode.InnerText.Substring(0, cursorPos.PosInTextNode);
                string textAfterCursor = cursorPos.ActualNode.InnerText.Substring(cursorPos.PosInTextNode, cursorPos.ActualNode.InnerText.Length - cursorPos.PosInTextNode);
                // Insert the character of the pressed keys after the cursor
                cursorPos.ActualNode.InnerText = $"{textBeforeNode}{text}{textAfterCursor}";
                cursorPos.SetPos(cursorPos.ActualNode, cursorPos.PosOnNode, cursorPos.PosInTextNode + text.Length);
                break;

            default:
                throw new ApplicationException(String.Format("InsertText: unknown CursorPos {0}", cursorPos.PosOnNode));
            }
            return(new InsertTextResult {
                ReplaceNode = replacementNode
            });
        }