Beispiel #1
0
        /// <summary>
        /// More http://www.w3.org/TR/REC-xml/#NT-Attribute.
        /// </summary>
        /// <param name="tag">The current tag token.</param>
        XmlToken AttributeName(XmlTagToken tag)
        {
            var c = GetNext();

            while (c.IsXmlName())
            {
                StringBuffer.Append(c);
                c = GetNext();
            }

            var name = FlushBuffer();

            if (!String.IsNullOrEmpty(tag.GetAttribute(name)))
            {
                throw XmlParseError.XmlUniqueAttribute.At(GetCurrentPosition());
            }

            tag.AddAttribute(name);

            if (c.IsSpaceCharacter())
            {
                do
                {
                    c = GetNext();
                }while (c.IsSpaceCharacter());
            }

            if (c != Symbols.Equality)
            {
                throw XmlParseError.XmlInvalidAttribute.At(GetCurrentPosition());
            }

            return(AttributeBeforeValue(tag));
        }
Beispiel #2
0
        /// <summary>
        /// More http://www.w3.org/TR/REC-xml/#NT-Attribute.
        /// </summary>
        /// <param name="c">The next input character.</param>
        /// <param name="q">The quote character.</param>
        /// <param name="tag">The current tag token.</param>
        XmlToken AttributeValue(Char c, Char q, XmlTagToken tag)
        {
            while (c != q)
            {
                if (c == Symbols.EndOfFile)
                {
                    throw XmlParseError.EOF.At(GetCurrentPosition());
                }

                if (c == Symbols.Ampersand)
                {
                    _stringBuffer.Append(CharacterReference(GetNext()).GetEntity());
                }
                else if (c == Symbols.LessThan)
                {
                    throw XmlParseError.XmlLtInAttributeValue.At(GetCurrentPosition());
                }
                else
                {
                    _stringBuffer.Append(c);
                }

                c = GetNext();
            }

            tag.SetAttributeValue(_stringBuffer.ToString());
            return(AttributeAfterValue(GetNext(), tag));
        }
Beispiel #3
0
        /// <summary>
        /// More http://www.w3.org/TR/REC-xml/#NT-Attribute.
        /// </summary>
        /// <param name="tag">The current tag token.</param>
        /// <param name="quote">The quote character.</param>
        XmlToken AttributeValue(XmlTagToken tag, Char quote)
        {
            var c = GetNext();

            while (c != quote)
            {
                if (c == Symbols.EndOfFile)
                {
                    throw XmlParseError.EOF.At(GetCurrentPosition());
                }

                if (c == Symbols.Ampersand)
                {
                    StringBuffer.Append(CharacterReference());
                }
                else if (c == Symbols.LessThan)
                {
                    throw XmlParseError.XmlLtInAttributeValue.At(GetCurrentPosition());
                }
                else
                {
                    StringBuffer.Append(c);
                }

                c = GetNext();
            }

            tag.SetAttributeValue(FlushBuffer());
            return(AttributeAfterValue(tag));
        }
Beispiel #4
0
        /// <summary>
        /// More http://www.w3.org/TR/REC-xml/#NT-Name.
        /// </summary>
        /// <param name="tag">The current tag token.</param>
        /// <returns>The emitted token.</returns>
        XmlToken TagName(XmlTagToken tag)
        {
            var c = GetNext();

            while (c.IsXmlName())
            {
                StringBuffer.Append(c);
                c = GetNext();
            }

            tag.Name = FlushBuffer();

            if (c == Symbols.EndOfFile)
            {
                throw XmlParseError.EOF.At(GetCurrentPosition());
            }

            if (c == Symbols.GreaterThan)
            {
                return(tag);
            }
            else if (c.IsSpaceCharacter())
            {
                return(AttributeBeforeName(tag));
            }
            else if (c == Symbols.Solidus)
            {
                return(TagSelfClosing(tag));
            }

            throw XmlParseError.XmlInvalidName.At(GetCurrentPosition());
        }
Beispiel #5
0
        /// <summary>
        /// More http://www.w3.org/TR/REC-xml/#NT-Attribute.
        /// </summary>
        /// <param name="tag">The current tag token.</param>
        XmlToken AttributeBeforeName(XmlTagToken tag)
        {
            var c = SkipSpaces();

            if (c == Symbols.Solidus)
            {
                return(TagSelfClosing(tag));
            }
            else if (c == Symbols.GreaterThan)
            {
                return(tag);
            }

            if (c == Symbols.EndOfFile)
            {
                throw XmlParseError.EOF.At(GetCurrentPosition());
            }

            if (c.IsXmlNameStart())
            {
                StringBuffer.Append(c);
                return(AttributeName(tag));
            }

            throw XmlParseError.XmlInvalidAttribute.At(GetCurrentPosition());
        }
Beispiel #6
0
        /// <summary>
        /// More http://www.w3.org/TR/REC-xml/#NT-Attribute.
        /// </summary>
        /// <param name="c">The next input character.</param>
        /// <param name="tag">The current tag token.</param>
        XmlToken AttributeBeforeName(Char c, XmlTagToken tag)
        {
            while (c.IsSpaceCharacter())
            {
                c = GetNext();
            }

            if (c == Symbols.Solidus)
            {
                return(TagSelfClosing(GetNext(), tag));
            }
            else if (c == Symbols.GreaterThan)
            {
                return(tag);
            }
            else if (c == Symbols.EndOfFile)
            {
                throw XmlParseError.EOF.At(GetCurrentPosition());
            }

            if (c.IsXmlNameStart())
            {
                _stringBuffer.Append(c);
                return(AttributeName(GetNext(), tag));
            }

            throw XmlParseError.XmlInvalidAttribute.At(GetCurrentPosition());
        }
Beispiel #7
0
        /// <summary>
        /// More http://www.w3.org/TR/REC-xml/#NT-Attribute.
        /// </summary>
        /// <param name="c">The next input character.</param>
        /// <param name="tag">The current tag token.</param>
        XmlToken AttributeBeforeValue(Char c, XmlTagToken tag)
        {
            while (c.IsSpaceCharacter())
                c = GetNext();

            if (c == Symbols.DoubleQuote || c== Symbols.SingleQuote)
                return AttributeValue(GetNext(), c, tag);

            throw XmlParseError.XmlInvalidAttribute.At(GetCurrentPosition());
        }
Beispiel #8
0
        /// <summary>
        /// More http://www.w3.org/TR/REC-xml/#NT-Attribute.
        /// </summary>
        /// <param name="tag">The current tag token.</param>
        XmlToken AttributeBeforeValue(XmlTagToken tag)
        {
            var c = SkipSpaces();

            if (c != Symbols.DoubleQuote && c != Symbols.SingleQuote)
            {
                throw XmlParseError.XmlInvalidAttribute.At(GetCurrentPosition());
            }

            return(AttributeValue(tag, c));
        }
Beispiel #9
0
        /// <summary>
        /// More http://www.w3.org/TR/REC-xml/#NT-Attribute.
        /// </summary>
        /// <param name="c">The next input character.</param>
        /// <param name="tag">The current tag token.</param>
        XmlToken AttributeAfterValue(Char c, XmlTagToken tag)
        {
            if (c.IsSpaceCharacter())
                return AttributeBeforeName(GetNext(), tag);
            else if (c == Symbols.Solidus)
                return TagSelfClosing(GetNext(), tag);
            else if (c == Symbols.GreaterThan)
                return tag;

            throw XmlParseError.XmlInvalidAttribute.At(GetCurrentPosition());
        }
Beispiel #10
0
        /// <summary>
        /// More http://www.w3.org/TR/REC-xml/#d0e2480.
        /// </summary>
        /// <param name="c">The next input character.</param>
        /// <param name="tag">The current tag token.</param>
        XmlToken TagSelfClosing(Char c, XmlTagToken tag)
        {
            tag.IsSelfClosing = true;

            if (c == Symbols.GreaterThan)
                return tag;
            
            if (c == Symbols.EndOfFile)
                throw XmlParseError.EOF.At(GetCurrentPosition());

            throw XmlParseError.XmlInvalidName.At(GetCurrentPosition());
        }
Beispiel #11
0
        /// <summary>
        /// More http://www.w3.org/TR/REC-xml/#d0e2480.
        /// </summary>
        /// <param name="tag">The current tag token.</param>
        XmlToken TagSelfClosing(XmlTagToken tag)
        {
            var c = GetNext();

            tag.IsSelfClosing = true;

            if (c == Symbols.GreaterThan)
            {
                return(tag);
            }

            if (c == Symbols.EndOfFile)
            {
                throw XmlParseError.EOF.At(GetCurrentPosition());
            }

            throw XmlParseError.XmlInvalidName.At(GetCurrentPosition());
        }
Beispiel #12
0
        /// <summary>
        /// More http://www.w3.org/TR/REC-xml/#NT-Attribute.
        /// </summary>
        /// <param name="tag">The current tag token.</param>
        XmlToken AttributeAfterValue(XmlTagToken tag)
        {
            var c = GetNext();

            if (c.IsSpaceCharacter())
            {
                return(AttributeBeforeName(tag));
            }
            else if (c == Symbols.Solidus)
            {
                return(TagSelfClosing(tag));
            }
            else if (c == Symbols.GreaterThan)
            {
                return(tag);
            }

            throw XmlParseError.XmlInvalidAttribute.At(GetCurrentPosition());
        }
Beispiel #13
0
        /// <summary>
        /// More http://www.w3.org/TR/REC-xml/#NT-Attribute.
        /// </summary>
        /// <param name="c">The next input character.</param>
        /// <param name="q">The quote character.</param>
        /// <param name="tag">The current tag token.</param>
        XmlToken AttributeValue(Char c, Char q, XmlTagToken tag)
        {
            while (c != q)
            {
                if (c == Symbols.EndOfFile)
                    throw XmlParseError.EOF.At(GetCurrentPosition());

                if (c == Symbols.Ampersand)
                    _stringBuffer.Append(CharacterReference(GetNext()));
                else if (c == Symbols.LessThan)
                    throw XmlParseError.XmlLtInAttributeValue.At(GetCurrentPosition());
                else 
                    _stringBuffer.Append(c);

                c = GetNext();
            }

            tag.SetAttributeValue(FlushBuffer());
            return AttributeAfterValue(GetNext(), tag);
        }
Beispiel #14
0
        /// <summary>
        /// More http://www.w3.org/TR/REC-xml/#NT-Name.
        /// </summary>
        /// <param name="c">The next input character.</param>
        /// <param name="tag">The current tag token.</param>
        /// <returns>The emitted token.</returns>
        XmlToken TagName(Char c, XmlTagToken tag)
        {
            while (c.IsXmlName())
            {
                _stringBuffer.Append(c);
                c = GetNext();
            }

            tag.Name = FlushBuffer();

            if (c == Symbols.EndOfFile)
                throw XmlParseError.EOF.At(GetCurrentPosition());

            if (c == Symbols.GreaterThan)
                return tag;
            else if (c.IsSpaceCharacter())
                return AttributeBeforeName(GetNext(), tag);
            else if (c == Symbols.Solidus)
                return TagSelfClosing(GetNext(), tag);

            throw XmlParseError.XmlInvalidName.At(GetCurrentPosition());
        }
Beispiel #15
0
        /// <summary>
        /// More http://www.w3.org/TR/REC-xml/#NT-Attribute.
        /// </summary>
        /// <param name="c">The next input character.</param>
        /// <param name="tag">The current tag token.</param>
        XmlToken AttributeName(Char c, XmlTagToken tag)
        {
            while (c.IsXmlName())
            {
                _stringBuffer.Append(c);
                c = GetNext();
            }

            var name = FlushBuffer();

            if (!String.IsNullOrEmpty(tag.GetAttribute(name)))
                throw XmlParseError.XmlUniqueAttribute.At(GetCurrentPosition());

            tag.AddAttribute(name);

            if (c.IsSpaceCharacter())
            {
                do c = GetNext();
                while (c.IsSpaceCharacter());
            }
            
            if (c == Symbols.Equality)
                return AttributeBeforeValue(GetNext(), tag);

            throw XmlParseError.XmlInvalidAttribute.At(GetCurrentPosition());
        }
Beispiel #16
0
        /// <summary>
        /// More http://www.w3.org/TR/REC-xml/#NT-Attribute.
        /// </summary>
        /// <param name="c">The next input character.</param>
        /// <param name="tag">The current tag token.</param>
        XmlToken AttributeBeforeName(Char c, XmlTagToken tag)
        {
            while (c.IsSpaceCharacter())
                c = GetNext();

            if (c == Symbols.Solidus)
                return TagSelfClosing(GetNext(), tag);
            else if (c == Symbols.GreaterThan)
                return tag;
            else if (c == Symbols.EndOfFile)
                throw XmlParseError.EOF.At(GetCurrentPosition());

            if (c.IsXmlNameStart())
            {
                _stringBuffer.Append(c);
                return AttributeName(GetNext(), tag);
            }

            throw XmlParseError.XmlInvalidAttribute.At(GetCurrentPosition());
        }
Beispiel #17
0
        /// <summary>
        /// More http://www.w3.org/TR/REC-xml/#d0e2480.
        /// </summary>
        /// <param name="c">The next input character.</param>
        /// <param name="tag">The current tag token.</param>
        XmlToken TagSelfClosing(Char c, XmlTagToken tag)
        {
            tag.IsSelfClosing = true;

            if (c == Symbols.GreaterThan)
                return tag;
            
            if (c == Symbols.EndOfFile)
                throw XmlParseError.EOF.At(GetCurrentPosition());

            throw XmlParseError.XmlInvalidName.At(GetCurrentPosition());
        }
Beispiel #18
0
        /// <summary>
        /// More http://www.w3.org/TR/REC-xml/#NT-Attribute.
        /// </summary>
        /// <param name="c">The next input character.</param>
        /// <param name="tag">The current tag token.</param>
        XmlToken AttributeAfterValue(Char c, XmlTagToken tag)
        {
            if (c.IsSpaceCharacter())
                return AttributeBeforeName(GetNext(), tag);
            else if (c == Symbols.Solidus)
                return TagSelfClosing(GetNext(), tag);
            else if (c == Symbols.GreaterThan)
                return tag;

            throw XmlParseError.XmlInvalidAttribute.At(GetCurrentPosition());
        }
Beispiel #19
0
        /// <summary>
        /// More http://www.w3.org/TR/REC-xml/#NT-Name.
        /// </summary>
        /// <param name="tag">The current tag token.</param>
        /// <returns>The emitted token.</returns>
        private XmlToken TagName(XmlTagToken tag)
        {
            var c = GetNext();

            while (c.IsXmlName())
            {
                StringBuffer.Append(c);
                c = GetNext();
            }

            tag.Name = FlushBuffer();

            if (c == Symbols.EndOfFile)
                throw XmlParseError.EOF.At(GetCurrentPosition());

            if (c == Symbols.GreaterThan)
            {
                return tag;
            }
            else if (c.IsSpaceCharacter())
            {
                return AttributeBeforeName(tag);
            }
            else if (c == Symbols.Solidus)
            {
                return TagSelfClosing(tag);
            }

            throw XmlParseError.XmlInvalidName.At(GetCurrentPosition());
        }
Beispiel #20
0
        /// <summary>
        /// More http://www.w3.org/TR/REC-xml/#NT-Attribute.
        /// </summary>
        /// <param name="tag">The current tag token.</param>
        private XmlToken AttributeBeforeValue(XmlTagToken tag)
        {
            var c = SkipSpaces();

            if (c != Symbols.DoubleQuote && c != Symbols.SingleQuote)
                throw XmlParseError.XmlInvalidAttribute.At(GetCurrentPosition());

            return AttributeValue(tag, c);
        }
Beispiel #21
0
        /// <summary>
        /// More http://www.w3.org/TR/REC-xml/#NT-Attribute.
        /// </summary>
        /// <param name="tag">The current tag token.</param>
        /// <param name="quote">The quote character.</param>
        private XmlToken AttributeValue(XmlTagToken tag, Char quote)
        {
            var c = GetNext();

            while (c != quote)
            {
                if (c == Symbols.EndOfFile)
                    throw XmlParseError.EOF.At(GetCurrentPosition());

                if (c == Symbols.LessThan)
                    throw XmlParseError.XmlLtInAttributeValue.At(GetCurrentPosition());

                if (c == Symbols.Ampersand)
                {
                    StringBuffer.Append(CharacterReference());
                }
                else
                {
                    StringBuffer.Append(c);
                }

                c = GetNext();
            }

            tag.SetAttributeValue(FlushBuffer());
            return AttributeAfterValue(tag);
        }
Beispiel #22
0
        /// <summary>
        /// More http://www.w3.org/TR/REC-xml/#NT-Attribute.
        /// </summary>
        /// <param name="tag">The current tag token.</param>
        private XmlToken AttributeBeforeName(XmlTagToken tag)
        {
            var c = SkipSpaces();

            if (c == Symbols.Solidus)
            {
                return TagSelfClosing(tag);
            }
            else if (c == Symbols.GreaterThan)
            {
                return tag;
            }

            if (c == Symbols.EndOfFile)
                throw XmlParseError.EOF.At(GetCurrentPosition());

            if (c.IsXmlNameStart())
            {
                StringBuffer.Append(c);
                return AttributeName(tag);
            }

            throw XmlParseError.XmlInvalidAttribute.At(GetCurrentPosition());
        }
Beispiel #23
0
        /// <summary>
        /// More http://www.w3.org/TR/REC-xml/#d0e2480.
        /// </summary>
        /// <param name="tag">The current tag token.</param>
        private XmlToken TagSelfClosing(XmlTagToken tag)
        {
            var c = GetNext();
            tag.IsSelfClosing = true;

            if (c == Symbols.GreaterThan)
            {
                return tag;
            }

            if (c == Symbols.EndOfFile)
                throw XmlParseError.EOF.At(GetCurrentPosition());

            throw XmlParseError.XmlInvalidName.At(GetCurrentPosition());
        }
Beispiel #24
0
        /// <summary>
        /// More http://www.w3.org/TR/REC-xml/#NT-Attribute.
        /// </summary>
        /// <param name="c">The next input character.</param>
        /// <param name="tag">The current tag token.</param>
        XmlToken AttributeBeforeValue(Char c, XmlTagToken tag)
        {
            while (c.IsSpaceCharacter())
                c = GetNext();

            if (c == Symbols.DoubleQuote || c== Symbols.SingleQuote)
                return AttributeValue(GetNext(), c, tag);

            throw XmlParseError.XmlInvalidAttribute.At(GetCurrentPosition());
        }
Beispiel #25
0
        /// <summary>
        /// More http://www.w3.org/TR/REC-xml/#NT-Attribute.
        /// </summary>
        /// <param name="c">The next input character.</param>
        /// <param name="q">The quote character.</param>
        /// <param name="tag">The current tag token.</param>
        XmlToken AttributeValue(Char c, Char q, XmlTagToken tag)
        {
            while (c != q)
            {
                if (c == Symbols.EndOfFile)
                    throw XmlParseError.EOF.At(GetCurrentPosition());

                if (c == Symbols.Ampersand)
                    _stringBuffer.Append(CharacterReference(GetNext()));
                else if (c == Symbols.LessThan)
                    throw XmlParseError.XmlLtInAttributeValue.At(GetCurrentPosition());
                else 
                    _stringBuffer.Append(c);

                c = GetNext();
            }

            tag.SetAttributeValue(FlushBuffer());
            return AttributeAfterValue(GetNext(), tag);
        }
Beispiel #26
0
        /// <summary>
        /// More http://www.w3.org/TR/REC-xml/#NT-Attribute.
        /// </summary>
        /// <param name="tag">The current tag token.</param>
        private XmlToken AttributeAfterValue(XmlTagToken tag)
        {
            var c = GetNext();

            if (c.IsSpaceCharacter())
            {
                return AttributeBeforeName(tag);
            }
            else if (c == Symbols.Solidus)
            {
                return TagSelfClosing(tag);
            }
            else if (c == Symbols.GreaterThan)
            {
                return tag;
            }

            throw XmlParseError.XmlInvalidAttribute.At(GetCurrentPosition());
        }