Beispiel #1
0
        /// <summary>
        /// This method returns the Node Text
        /// </summary>
        public string FormatNodeText()
        {
            // initial value
            string formatNodeText = "";

            // locals
            string openTag     = "<";
            string openTag2    = "</";
            string closingTag  = ">";
            string closingTag2 = "/>";
            string nil         = " nil=\"true\" ";
            int    nilIndex    = -1;

            // if this node has a value
            if (this.HasNodeValue)
            {
                // Several different types of items need to parsed out here
                // 1. Open and closing tags
                //     Example: <id>2</id>
                // 2. Nill Tag
                //     Example: <chat-client-sequence nil="true">
                // 3. Self closing tag (I made these names up)
                //     Example: <attachments/>

                // set the open and closing tag names so that can be replaced out
                string openTagName      = TextHelper.CombineStrings(openTag, this.NodeText, closingTag);
                string closingTagName   = TextHelper.CombineStrings(openTag2, this.NodeText, closingTag);
                string nilText          = TextHelper.CombineStrings(openTag, this.NodeText, nil, closingTag2);
                string selfClosing      = TextHelper.CombineStrings(openTag, this.NodeText, " ", closingTag2);
                int    selfClosingIndex = this.NodeText.IndexOf(selfClosing);
                bool   isSelfClosing    = (selfClosingIndex >= 0);
                nilIndex = this.NodeValue.IndexOf("nil=");

                // if nil
                if (nilIndex > 0)
                {
                    // use nodeText & reset the nodeText
                    nodeText = this.NodeText + " = null";

                    // set the FormattedNodeValue
                    this.FormattedNodeValue = null;
                }
                else
                {
                    // user nodeText & node value
                    nodeText = this.NodeText + " = " + this.NodeValue;
                }

                // replace out the open and closing tags
                nodeText = nodeText.Replace(openTagName, "");
                nodeText = nodeText.Replace(closingTagName, "");
                nodeText = nodeText.Replace(nilText, "");
                nodeText = nodeText.Replace(selfClosing, "");

                // set the startIndex
                int startIndex = nodeText.IndexOf("=");

                // if the Length exists
                if (nodeText.Length > startIndex)
                {
                    // set the formattedNodeValue
                    this.FormattedNodeValue = nodeText.Substring(startIndex + 1).Trim();
                }

                // if this is a selfClosing node
                if (isSelfClosing)
                {
                    // replace out the = sign
                    nodeText = nodeText.Replace("=", "");
                }
            }
            else
            {
                // use text only
                nodeText = this.NodeText;
            }

            // replace out the text
            nodeText = RVictorveTags(nodeText);

            // return value
            return(formatNodeText);
        }