示例#1
0
        // This method is used in token view when ExpandEntities is false and
        // IgnoreEntities is false to return each text and entity reference as an
        // individual record.
        private bool ParseLiteralTokens(XmlScanner scanner, XmlBasicTokenInfo currToken, int newDepth,
                                        EntityHandling ehMode, ref int lastToken) {
            //String rawValue = String.Empty;
            String name = String.Empty, dataType = _StringName;
            XmlNodeType nodeType = XmlNodeType.Text;
            int startPos = -1, erPos = -1;
            int LineNum = _Scanner.LineNum;
            int LinePos = _Scanner.LinePos;

            bool hasToken = false/*, hasER = false*/, retValue = false;
            char ch='\0';

            int state = 2;
            _StringBuilder.Length = 0;

            do {
                switch (state) {
                    case 2:
                        erPos = scanner.CurrentPos;
                        lastToken = scanner.ScanLiteral(true, false, false, false);
                        switch (lastToken) {
                            case XmlToken.EOF: // reached the end of the literal.
                                state = -1;
                                if (!hasToken) {
                                    retValue = true;
                                    goto cleanup;
                                }
                                goto seeToken;
                            case XmlToken.TEXT:
                                startPos = (hasToken == true) ? startPos : scanner.StartPos;
                                _StringBuilder.Append(scanner.InternalBuffer, scanner.TextOffset, scanner.TextLength);
                                hasToken = true;
                                nodeType = XmlNodeType.Text;
                                state = 2;
                                break;
                            case XmlToken.ENTITYREF:
                                startPos = (hasToken == true) ? startPos : scanner.StartPos - 1;
                                ch = scanner.ScanNamedEntity();
                                name = scanner.GetTextAtom();
                                //
                                //  ch == 0 if general entity
                                //  ch != 0 if build in entity, for example: &lt
                                //

                                if (ch == 0 && _CheckNamespaces && _Scanner.Colon() != -1)
                                    throw new XmlException(Res.Xml_BadNameChar, XmlException.BuildCharExceptionStr(':'), _Scanner.LineNum, _Scanner.LinePos);

                                if (ch != 0) {
                                    _StringBuilder.Append(ch);

                                    dataType = "Char";
                                    scanner.Advance();
                                    hasToken = true;
                                    //hasER = true;
                                    _NextState = 2;
                                    name = String.Empty;
                                    nodeType = XmlNodeType.Text;
                                }
                                else if (hasToken) {
                                    // First return the text we have up to this point.
                                    state = 11;
                                }
                                else {
                                    // Return the entity reference as a node.
                                    state = 10;
                                    nodeType = XmlNodeType.EntityReference;
                                }
                                break;
                            case XmlToken.NUMENTREF:
                                startPos = (hasToken == true) ? startPos : scanner.StartPos - 1;
                                hasToken = true;
                                //hasER = true;
                                _StringBuilder.Append(scanner.ScanDecEntity());
                                state = 2;
                                break;
                            case XmlToken.HEXENTREF:
                                startPos = (hasToken == true) ? startPos : scanner.StartPos - 1;
                                hasToken = true;
                                //hasER = true;
                                _StringBuilder.Append(scanner.ScanHexEntity());
                                state = 2;
                                break;
                            default:
                                throw new XmlException(Res.Xml_InternalError);
                        }
                        break;
                    case 9:
                        scanner.Advance();
                        hasToken = true;
                        //hasER = true;
                        state = 2;
                        goto seeToken;
                    case 10:
                        scanner.Advance();
                        hasToken = true;
                        //hasER = true;
                        state = 2;
                        // general entity special case
                        currToken.Value = String.Empty;
                        LinePos += 1;
                        goto otherToken;
                    case 11:
                        scanner.CurrentPos = erPos;
                        state = 2;
                        name = String.Empty;
                        goto seeToken;
                    case 12:
                        state = 2;
                        ParseTag();
                        goto cleanup;
                    default:
                        Debug.Assert(false, "unknown state within ParseBeginTag()");
                        break;
                }
            } while (true);
            seeToken:
            currToken.SetValue(_StringBuilder);
            dataType = _StringName;

            //
            // there is no rawValue
            // if (hasER)
            //  rawValue = scanner.GetText(startPos, scanner.CurrentPos - startPos);
            //currToken.RawValue = rawValue;

            otherToken:
            currToken.Name = name;
            currToken.LineNum = LineNum;
            currToken.LinePos = LinePos;
            currToken.NodeType = nodeType;
            currToken.Depth = newDepth;
            cleanup:
            return retValue;
        }