Exemplo n.º 1
0
 public TiXmlAttribute Find(string _name)
 {
     for (TiXmlAttribute node = sentinel.next; node != sentinel; node = node.next)
     {
         if (string.Compare(node.Name(), _name) == 0)
         {
             return(node);
         }
     }
     return(null);
 }
Exemplo n.º 2
0
        protected void CopyTo(TiXmlElement target)
        {
            // superclass:
            base.CopyTo(target);

            // Element class:
            // Clone the attributes, then clone the children.
            TiXmlAttribute attribute = null;

            for (attribute = attributeSet.First(); attribute != null; attribute = attribute.Next())
            {
                target.SetAttribute(attribute.Name(), attribute.Value());
            }

            TiXmlNode node = null;

            for (node = firstChild; node != null; node = node.NextSibling())
            {
                target.LinkEndChild(node.Clone());
            }
        }
Exemplo n.º 3
0
        /*	Attribtue parsing starts: next char past '<'
         *                                       returns: next char past '>'
         */
        public override int Parse(string p, int index, TiXmlParsingData data, int encoding)
        {
            index = SkipWhiteSpace(p, index, encoding);
            TiXmlDocument document = GetDocument();

            if (p == null || index < 0 || index >= p.Length)
            {
                if (document != null)
                {
                    document.SetError(ErrorType.TIXML_ERROR_PARSING_ELEMENT, null, 0, null, encoding);
                }
                return(0);
            }

            if (data != null)
            {
                data.Stamp(p, index, encoding);
                location = data.Cursor();
            }

            if (p[index] != '<')
            {
                if (document != null)
                {
                    document.SetError(ErrorType.TIXML_ERROR_PARSING_ELEMENT, p, index, data, encoding);
                }
                return(0);
            }

            index = SkipWhiteSpace(p, index + 1, encoding);

            // Read the name.
            int pErr = index;

            index = ReadName(p, index, ref value, encoding);
            if (index < 0 || index >= p.Length)
            {
                if (document != null)
                {
                    document.SetError(ErrorType.TIXML_ERROR_FAILED_TO_READ_ELEMENT_NAME, p, pErr, data, encoding);
                }
                return(INVALID_STRING_INDEX);
            }

            string endTag = "</";

            endTag += value;
            endTag += ">";

            // Check for and read attributes. Also look for an empty
            // tag or an end tag.
            while (index >= 0 && index < p.Length)
            {
                pErr  = index;
                index = SkipWhiteSpace(p, index, encoding);
                if (index < 0 || index >= p.Length)
                {
                    if (document != null)
                    {
                        document.SetError(ErrorType.TIXML_ERROR_READING_ATTRIBUTES, p, pErr, data, encoding);
                    }
                    return(-1);
                }
                if (p[index] == '/')
                {
                    ++index;
                    // Empty tag.
                    if (p[index] != '>')
                    {
                        if (document != null)
                        {
                            document.SetError(ErrorType.TIXML_ERROR_PARSING_EMPTY, p, index, data, encoding);
                        }
                        return(0);
                    }
                    return(index + 1);
                }
                else if (p[index] == '>')
                {
                    // Done with attributes (if there were any.)
                    // Read the value -- which can include other
                    // elements -- read the end tag, and return.
                    ++index;
                    index = ReadValue(p, index, data, encoding); // Note this is an Element method, and will set the error if one happens.
                    if (index < 0 || index >= p.Length)
                    {                                            // We were looking for the end tag, but found nothing.
                                                                 // Fix for [ 1663758 ] Failure to report error on bad XML
                        if (document != null)
                        {
                            document.SetError(ErrorType.TIXML_ERROR_READING_END_TAG, p, index, data, encoding);
                        }
                        return(INVALID_STRING_INDEX);
                    }

                    // We should find the end tag now
                    if (StringEqual(p, index, endTag, false, encoding))
                    {
                        index += endTag.Length;
                        return(index);
                    }
                    else
                    {
                        if (document != null)
                        {
                            document.SetError(ErrorType.TIXML_ERROR_READING_END_TAG, p, index, data, encoding);
                        }
                        return(INVALID_STRING_INDEX);
                    }
                }
                else
                {
                    // Try to read an attribute:
                    TiXmlAttribute attrib = new TiXmlAttribute();
                    if (attrib == null)
                    {
                        if (document != null)
                        {
                            document.SetError(ErrorType.TIXML_ERROR_OUT_OF_MEMORY, p, pErr, data, encoding);
                        }
                        return(-1);
                    }

                    attrib.SetDocument(document);
                    pErr  = index;
                    index = attrib.Parse(p, index, data, encoding);

                    if (index < 0 || index >= p.Length)
                    {
                        if (document != null)
                        {
                            document.SetError(ErrorType.TIXML_ERROR_PARSING_ELEMENT, p, pErr, data, encoding);
                        }
                        //delete attrib;
                        return(INVALID_STRING_INDEX);
                    }

                    // Handle the strange case of double attributes:
                    TiXmlAttribute node = attributeSet.Find(attrib.Name());
                    if (node != null)
                    {
                        node.SetValue(attrib.Value());
                        //delete attrib;
                        return(INVALID_STRING_INDEX);
                    }

                    attributeSet.Add(attrib);
                }
            }
            return(index);
        }