Exemple #1
0
 public override bool Visit(TiXmlDeclaration declaration)
 {
     DoIndent();
     declaration.Print(buffer, 0);
     DoLineBreak();
     return(true);
 }
Exemple #2
0
        protected void CopyTo(TiXmlDeclaration target)
        {
            base.CopyTo(target);

            target.version    = version;
            target.encoding   = encoding;
            target.standalone = standalone;
        }
Exemple #3
0
        /// <summary>
        /// Creates a copy of this Declaration and returns it.
        /// </summary>
        public override TiXmlNode Clone()
        {
            TiXmlDeclaration clone = new TiXmlDeclaration();

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

            CopyTo(clone);
            return(clone);
        }
Exemple #4
0
        /// <summary>
        /// Parse the given null terminated block of xml data. Passing in an encoding to this
        /// method (either TIXML_ENCODING_LEGACY or TIXML_ENCODING_UTF8 will force TinyXml
        /// to use that encoding, regardless of what TinyXml might otherwise try to detect.
        /// </summary>
        public override int Parse(string p, int index, TiXmlParsingData prevData /* = null*/, int encoding /* = TIXML_DEFAULT_ENCODING*/)
        {
            ClearError();

            // Parse away, at the document level. Since a document
            // contains nothing but other tags, most of what happens
            // here is skipping white space.
            //if ( !p || !*p )
            if (p == null || index < 0 || index >= p.Length)
            {
                SetError(ErrorType.TIXML_ERROR_DOCUMENT_EMPTY, null, 0, null, TiXmlEncoding.TIXML_ENCODING_UNKNOWN);
                return(0);
            }

            // Note that, for a document, this needs to come
            // before the while space skip, so that parsing
            // starts from the pointer we are given.
            location.Clear();
            if (prevData != null)
            {
                location.row = prevData.cursor.row;
                location.col = prevData.cursor.col;
            }
            else
            {
                location.row = 0;
                location.col = 0;
            }
            TiXmlParsingData data = new TiXmlParsingData(p, index, TabSize(), location.row, location.col);

            location = data.Cursor();
#if UNUSED
            if (encoding == TiXmlEncoding.TIXML_ENCODING_UNKNOWN)
            {
                // Check for the Microsoft UTF-8 lead bytes.
                const unsigned char *pU = (const unsigned char *)p;
                if (*(pU + 0) && *(pU + 0) == TIXML_UTF_LEAD_0 &&
                    *(pU + 1) && *(pU + 1) == TIXML_UTF_LEAD_1 &&
                    *(pU + 2) && *(pU + 2) == TIXML_UTF_LEAD_2)
                {
                    encoding        = TIXML_ENCODING_UTF8;
                    useMicrosoftBOM = true;
                }
            }
#endif
            index = SkipWhiteSpace(p, index, encoding);
            //if ( !p )
            if (index < 0)
            {
                SetError(ErrorType.TIXML_ERROR_DOCUMENT_EMPTY, null, 0, null, TiXmlEncoding.TIXML_ENCODING_UNKNOWN);
                return(-1);
            }

            while (index >= 0 && index < p.Length)
            {
                TiXmlNode node = Identify(p, index, encoding);
                if (node != null)
                {
                    index = node.Parse(p, index, data, encoding);
                    LinkEndChild(node);
                }
                else
                {
                    break;
                }

                // Did we get encoding info?
                if (encoding == TiXmlEncoding.TIXML_ENCODING_UNKNOWN && node.ToDeclaration() != null)
                {
                    TiXmlDeclaration dec = node.ToDeclaration();
                    string           enc = dec.Encoding();
                    //assert( enc );

                    if (enc.Length == 0 /**enc == 0 */)
                    {
                        encoding = TiXmlEncoding.TIXML_ENCODING_UTF8;
                    }
                    else if (StringEqual(enc, 0, "UTF-8", true, TiXmlEncoding.TIXML_ENCODING_UNKNOWN))
                    {
                        encoding = TiXmlEncoding.TIXML_ENCODING_UTF8;
                    }
                    else if (StringEqual(enc, 0, "UTF8", true, TiXmlEncoding.TIXML_ENCODING_UNKNOWN))
                    {
                        encoding = TiXmlEncoding.TIXML_ENCODING_UTF8;                           // incorrect, but be nice
                    }
                    else
                    {
                        encoding = TiXmlEncoding.TIXML_ENCODING_LEGACY;
                    }
                }

                index = SkipWhiteSpace(p, index, encoding);
            }

            // Was this empty?
            if (firstChild == null)
            {
                SetError(ErrorType.TIXML_ERROR_DOCUMENT_EMPTY, null, 0, null, encoding);
                return(INVALID_STRING_INDEX);
            }

            // All is well.
            return(index);
        }
Exemple #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);
        }
Exemple #6
0
 /// <summary>
 /// Visit a declaration
 /// </summary>
 public virtual bool Visit(TiXmlDeclaration declaration)
 {
     return(true);
 }
Exemple #7
0
 public TiXmlDeclaration(TiXmlDeclaration copy)
     : base(TiXmlNode.NodeType.DECLARATION)
 {
     copy.CopyTo(this);
 }