コード例 #1
0
ファイル: XmlTokenizer.cs プロジェクト: zidanfei/AngleSharp
        /// <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));
        }
コード例 #2
0
ファイル: XmlTokenizer.cs プロジェクト: mganss/AngleSharp
        /// <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));
        }
コード例 #3
0
ファイル: XmlTokenizer.cs プロジェクト: zidanfei/AngleSharp
        /// <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));
        }
コード例 #4
0
ファイル: XmlTokenizer.cs プロジェクト: zidanfei/AngleSharp
        /// <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());
        }
コード例 #5
0
ファイル: XmlTokenizer.cs プロジェクト: zidanfei/AngleSharp
        /// <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());
        }
コード例 #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());
        }
コード例 #7
0
ファイル: XmlTokenizer.cs プロジェクト: howej/AngleSharp
        /// <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());
        }
コード例 #8
0
ファイル: XmlTokenizer.cs プロジェクト: zidanfei/AngleSharp
        /// <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));
        }
コード例 #9
0
ファイル: XmlTokenizer.cs プロジェクト: howej/AngleSharp
        /// <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());
        }
コード例 #10
0
ファイル: XmlTokenizer.cs プロジェクト: howej/AngleSharp
        /// <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());
        }
コード例 #11
0
ファイル: XmlTokenizer.cs プロジェクト: zidanfei/AngleSharp
        /// <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());
        }
コード例 #12
0
ファイル: XmlTokenizer.cs プロジェクト: zidanfei/AngleSharp
        /// <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());
        }
コード例 #13
0
ファイル: XmlTokenizer.cs プロジェクト: howej/AngleSharp
        /// <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);
        }
コード例 #14
0
ファイル: XmlTokenizer.cs プロジェクト: howej/AngleSharp
        /// <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());
        }
コード例 #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());
        }
コード例 #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());
        }
コード例 #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());
        }
コード例 #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());
        }
コード例 #19
0
ファイル: XmlTokenizer.cs プロジェクト: Wojdav/AngleSharp
        /// <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());
        }
コード例 #20
0
ファイル: XmlTokenizer.cs プロジェクト: Wojdav/AngleSharp
        /// <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);
        }
コード例 #21
0
ファイル: XmlTokenizer.cs プロジェクト: Wojdav/AngleSharp
        /// <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);
        }
コード例 #22
0
ファイル: XmlTokenizer.cs プロジェクト: Wojdav/AngleSharp
        /// <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());
        }
コード例 #23
0
ファイル: XmlTokenizer.cs プロジェクト: Wojdav/AngleSharp
        /// <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());
        }
コード例 #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());
        }
コード例 #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);
        }
コード例 #26
0
ファイル: XmlTokenizer.cs プロジェクト: Wojdav/AngleSharp
        /// <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());
        }