Пример #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);
        }
Пример #3
0
        /// <summary>
        /// [internal use] Creates a new Element and returns it.
        /// </summary>
        public override TiXmlNode Clone()
        {
            TiXmlText clone = null;

            clone = new TiXmlText("");

            if (clone == null)
            {
                return(null);
            }

            CopyTo(clone);
            return(clone);
        }
Пример #4
0
        /// <summary>
        /// [internal use]
        /// Reads the "value" of the element -- another element, or text.
        /// This should terminate with the current end tag.
        /// </summary>
        protected int ReadValue(string p, int index, TiXmlParsingData data, int encoding)
        {
            TiXmlDocument document = GetDocument();

            // Read in text and elements in any order.
            int pWithWhiteSpace = index;

            index = SkipWhiteSpace(p, index, encoding);

            while (index >= 0 && index < p.Length)
            {
                if (p[index] != '<')
                {
                    // Take what we have, make a text element.
                    TiXmlText textNode = new TiXmlText("");

                    if (textNode == null)
                    {
                        if (document == null)
                        {
                            document.SetError(ErrorType.TIXML_ERROR_OUT_OF_MEMORY, null, 0, null, encoding);
                        }
                        return(INVALID_STRING_INDEX);
                    }

                    if (IsWhiteSpaceCondensed())
                    {
                        index = textNode.Parse(p, index, data, encoding);
                    }
                    else
                    {
                        // Special case: we want to keep the white space
                        // so that leading spaces aren't removed.
                        index = textNode.Parse(p, pWithWhiteSpace, data, encoding);
                    }

                    if (!textNode.Blank())
                    {
                        LinkEndChild(textNode);
                    }
                    //else
                    //	delete textNode;
                }
                else
                {
                    // We hit a '<'
                    // Have we hit a new element or an end tag? This could also be
                    // a TiXmlText in the "CDATA" style.
                    if (StringEqual(p, index, "</", false, encoding))
                    {
                        return(index);
                    }
                    else
                    {
                        TiXmlNode node = Identify(p, index, encoding);
                        if (node != null)
                        {
                            index = node.Parse(p, index, data, encoding);
                            LinkEndChild(node);
                        }
                        else
                        {
                            return(-1);
                        }
                    }
                }
                pWithWhiteSpace = index;
                index           = SkipWhiteSpace(p, index, encoding);
            }

            if (index < 0)
            {
                if (document != null)
                {
                    document.SetError(ErrorType.TIXML_ERROR_READING_ELEMENT_VALUE, null, 0, null, encoding);
                }
            }
            return(index);
        }
Пример #5
0
        /// <summary>
        /// Figure out what is at *p, and parse it. Returns null if it is not an xml node.
        /// </summary>
        protected TiXmlNode Identify(string p, int index, int encoding)
        {
            TiXmlNode returnNode = null;

            index = SkipWhiteSpace(p, index, encoding);
            if (p == null || index < 0 || index >= p.Length || p[index] != '<')
            {
                return(null);
            }

            TiXmlDocument doc = GetDocument();

            index = SkipWhiteSpace(p, index, encoding);

            if (index < 0 || index >= p.Length)
            {
                return(null);
            }

            // What is this thing?
            // - Elements start with a letter or underscore, but xml is reserved.
            // - Comments: <!--
            // - Decleration: <?xml
            // - Everthing else is unknown to tinyxml.
            //

            const string xmlHeader     = "<?xml";
            const string commentHeader = "<!--";
            const string dtdHeader     = "<!";
            const string cdataHeader   = "<![CDATA[";

            if (StringEqual(p, index, xmlHeader, true, encoding))
            {
#if UNUSED
                TIXML_LOG("XML parsing Declaration\n");
#endif
                returnNode = new TiXmlDeclaration();
            }
            else if (StringEqual(p, index, commentHeader, false, encoding))
            {
#if UNUSED
                TIXML_LOG("XML parsing Comment\n");
#endif
                returnNode = new TiXmlComment();
            }
            else if (StringEqual(p, index, cdataHeader, false, encoding))
            {
#if UNUSED
                TIXML_LOG("XML parsing CDATA\n");
#endif
                TiXmlText text = new TiXmlText("");
                text.SetCDATA(true);
                returnNode = text;
            }
            else if (StringEqual(p, index, dtdHeader, false, encoding))
            {
#if UNUSED
                TIXML_LOG("XML parsing Unknown(1)\n");
#endif
                returnNode = new TiXmlUnknown();
            }
            else if (IsAlpha(p[index + 1], encoding) || p[index + 1] == '_')
            {
#if UNUSED
                TIXML_LOG("XML parsing Element\n");
#endif
                returnNode = new TiXmlElement("");
            }
            else
            {
#if UNUSED
                TIXML_LOG("XML parsing Unknown(2)\n");
#endif
                returnNode = new TiXmlUnknown();
            }

            if (returnNode != null)
            {
                // Set the parent, so it can report errors
                returnNode.parent = this;
            }
            else
            {
                if (doc != null)
                {
                    doc.SetError(ErrorType.TIXML_ERROR_OUT_OF_MEMORY, null, 0, null, TiXmlEncoding.TIXML_ENCODING_UNKNOWN);
                }
            }
            return(returnNode);
        }
Пример #6
0
 /// <summary>
 /// Visit a text node
 /// </summary>
 public virtual bool Visit(TiXmlText text)
 {
     return(true);
 }
Пример #7
0
 public TiXmlText(TiXmlText copy) : base(TiXmlNode.NodeType.TEXT)
 {
     copy.CopyTo(this);
 }
Пример #8
0
 protected void CopyTo(TiXmlText target)
 {
     base.CopyTo(target);
     target.cdata = cdata;
 }