Пример #1
0
 public override bool Visit(TiXmlText text)
 {
     if (text.CDATA())
     {
         DoIndent();
         buffer.Append("<![CDATA[");
         buffer.Append(text.Value());
         buffer.Append("]]>");
         DoLineBreak();
     }
     else if (simpleTextPrint)
     {
         StringBuilder str = new StringBuilder();
         TiXmlBase.EncodeString(text.Value(), str);
         buffer.Append(str);
     }
     else
     {
         DoIndent();
         StringBuilder str = new StringBuilder();
         TiXmlBase.EncodeString(text.Value(), str);
         buffer.Append(str);
         DoLineBreak();
     }
     return(true);
 }
Пример #2
0
        /** Convenience function for easy access to the text inside an element. Although easy
         *      and concise, GetText() is limited compared to getting the TiXmlText child
         *      and accessing it directly.
         *
         *      If the first child of 'this' is a TiXmlText, the GetText()
         *      returns the character string of the Text node, else null is returned.
         *
         *      This is a convenient method for getting the text of simple contained text:
         *      @verbatim
         *      <foo>This is text</foo>
         *      const char* str = fooElement.GetText();
         *      @endverbatim
         *
         *      'str' will be a pointer to "This is text".
         *
         *      Note that this function can be misleading. If the element foo was created from
         *      this XML:
         *      @verbatim
         *      <foo><b>This is text</b></foo>
         *      @endverbatim
         *
         *      then the value of str would be null. The first child node isn't a text node, it is
         *      another element. From this XML:
         *      @verbatim
         *      <foo>This is <b>text</b></foo>
         *      @endverbatim
         *      GetText() will return "This is ".
         *
         *      WARNING: GetText() accesses a child node - don't become confused with the
         *                       similarly named TiXmlHandle::Text() and TiXmlNode::ToText() which are
         *                       safe type casts on the referenced node.
         */
        public string GetText()
        {
            TiXmlNode child = this.FirstChild();

            if (child != null)
            {
                TiXmlText childText = child.ToText();
                if (childText != null)
                {
                    return(childText.Value());
                }
            }
            return(null);
        }