예제 #1
0
파일: NodeReader.cs 프로젝트: OakRaven/ltaf
        private ProcessingInstruction ParseProcessingInstruction()
        {
            int    startPos = _pos;
            string prefix = null, localName = null;

            int index = _pos + 2;           // Skip the <?

            if (!ParseName(ref index, out prefix, out localName))
            {
                return(null);
            }
            ;

            ProcessingInstruction result = new ProcessingInstruction();

            result.SetName(prefix, localName);

            if (!ParseAttributes(ref index, result.Attributes))
            {
                return(null);
            }

            char c = _text[index];

            if (c == '?')
            {
                index++;
                if (index >= _length)
                {
                    return(null);
                }
                c = _text[index];
            }
            if (c != '>')
            {
                // Everything worked, but this IS not a PI tag, not closed yet
                return(null);
            }
            _pos = index + 1;
            result.SetPosition(startPos, index);
            return(result);
        }
예제 #2
0
파일: NodeReader.cs 프로젝트: OakRaven/ltaf
        public Node ReadNext()
        {
            int startText = -1;

            if (_previouslyReadNode != null)
            {
                Node node = _previouslyReadNode;
                _previouslyReadNode = null;
                return(node);
            }
            for (; _pos < _length - 1 /* we do this -1 since there is no possible node that only has 1 char */; _pos++)
            {
                int  backupPos = _pos;
                char c         = _text[_pos];
                switch (c)
                {
                case '<':
                    if (_text[_pos + 1] == '/')
                    {
                        ElementCloseTag closeTag = ParseClosingTag();
                        if (closeTag == null)
                        {
                            //here we should deal with non-element, only Text?
                            if (startText == -1)
                            {
                                startText = _pos;
                            }
                        }
                        else
                        {
                            if (startText != -1)
                            {
                                TextNode textNode = CheckForMissingText(startText, backupPos, closeTag);
                                if (textNode != null)
                                {
                                    return(textNode);
                                }
                            }
                            return(closeTag);
                        }
                    }
                    else if (_text[_pos + 1] == '!')
                    {
                        Node result = null;
                        if (_pos + 3 < _length && _text[_pos + 2] == '-' && _text[_pos + 3] == '-')
                        {
                            result = ParseComment();
                        }
                        else
                        {
                            result = ParseDocumentType();
                        }
                        if (result == null)
                        {
                            if (startText == -1)
                            {
                                startText = _pos;
                            }
                            break;
                        }
                        else if (startText != -1)
                        {
                            TextNode textNode = CheckForMissingText(startText, backupPos, result);                                     //backupPos +1
                            if (textNode != null)
                            {
                                return(textNode);
                            }
                        }
                        return(result);
                    }
                    else if (_text[_pos + 1] == '?')
                    {
                        ProcessingInstruction piTag = ParseProcessingInstruction();
                        if (piTag == null)
                        {
                            //here we should deal with non-element, only Text?
                            if (startText == -1)
                            {
                                startText = _pos;
                            }
                        }
                        else
                        {
                            if (startText != -1)
                            {
                                TextNode textNode = CheckForMissingText(startText, backupPos, piTag);
                                if (textNode != null)
                                {
                                    return(textNode);
                                }
                            }
                            return(piTag);
                        }
                    }
                    else
                    {
                        Element element = ParseStartTag();
                        if (element != null)
                        {
                            if (startText != -1)
                            {
                                TextNode textNode = CheckForMissingText(startText, backupPos, element);
                                if (textNode != null)
                                {
                                    return(textNode);
                                }
                            }
                            return(element);
                        }
                        else
                        {
                            //here we should deal with non-element, only Text?
                            if (startText == -1)
                            {
                                startText = _pos;
                            }
                        }
                    }
                    break;

                //					case '\r': case '\n':
                //						// only if this is first character from text it will be ignored
                //						break;
                default:
                    if (startText == -1)
                    {
                        startText = _pos;
                    }
                    break;
                }
            }
            if (startText == -1 && _pos == _length - 1)
            {
                startText = _pos;
                _pos++;
            }
            if (startText != -1)
            {
                TextNode textNode = CheckForMissingText(startText, _length, null);
                _pos = _length;
                if (textNode != null)
                {
                    return(textNode);
                }
            }

            return(null);
        }