示例#1
0
        protected void ParseNotation()
        {
            Token       token    = Expect(Scanner.IDENTIFIER);
            DTDNotation notation = new DTDNotation(token.Value);

            Dtd.Notations[notation.Name] = notation;
            Dtd.Items.Add(notation);

            token = Expect(Scanner.IDENTIFIER);

            if (token.Value.Equals("SYSTEM"))
            {
                DTDSystem sys = new DTDSystem();
                token = Expect(Scanner.STRING);

                sys.System          = token.Value;
                notation.ExternalId = sys;
            }
            else if (token.Value.Equals("PUBLIC"))
            {
                DTDPublic pub = new DTDPublic();
                token = Expect(Scanner.STRING);

                pub.Pub    = token.Value;
                pub.System = null;

                // For <!NOTATION>, you can have PUBLIC PubidLiteral without
                // a SystemLiteral
                token = Scanner.Peek();
                if (token.Type == Scanner.STRING)
                {
                    token      = Scanner.Get();
                    pub.System = token.Value;
                }

                notation.ExternalId = pub;
            }
            Expect(Scanner.GT);
        }
示例#2
0
        protected void ParseEntityDef(DTDEntity entity)
        {
            Token token = Scanner.Get();

            if (token.Type == Scanner.STRING)
            {
                // Only set the entity value if it hasn't been set yet
                // XML 1.0 spec says that you use the first value of
                // an entity, not the most recent.
                if (entity.Value == null)
                {
                    entity.Value = token.Value;
                }
            }
            else if (token.Type == Scanner.IDENTIFIER)
            {
                if (token.Value.Equals("SYSTEM"))
                {
                    DTDSystem sys = new DTDSystem();
                    token = Expect(Scanner.STRING);

                    sys.System        = token.Value;
                    entity.ExternalId = sys;
                }
                else if (token.Value.Equals("PUBLIC"))
                {
                    DTDPublic pub = new DTDPublic();

                    token             = Expect(Scanner.STRING);
                    pub.Pub           = token.Value;
                    token             = Expect(Scanner.STRING);
                    pub.System        = token.Value;
                    entity.ExternalId = pub;
                }
                else
                {
                    throw new DTDParseException(Scanner.GetUriId(),
                                                "Invalid External ID specification",
                                                Scanner.GetLineNumber(), Scanner.GetColumn());
                }


                // ISSUE: isParsed is set to TRUE if this is a Parameter Entity
                //     Reference (assuming this is because Parameter Entity
                //     external references are parsed, whereas General Entity
                //     external references are irrelevant for this product).
                //     However, NDATA is only valid if this is
                //     a General Entity Reference. So, "if" conditional should
                //     be (!entity.isParsed) rather than (entity.isParsed).
                //
                //Entity Declaration
                // [70] EntityDecl ::= GEDecl | PEDecl
                // [71] GEDecl ::= '<!ENTITY' S Name S EntityDef S? '>'
                // [72] PEDecl ::= '<!ENTITY' S '%' S Name S PEDef S? '>'
                // [73] EntityDef ::= EntityValue | (ExternalID NDataDecl?)
                // [74] PEDef ::= EntityValue | ExternalID
                //External Entity Declaration
                // [75] ExternalID ::= 'SYSTEM' S SystemLiteral
                //          | 'PUBLIC' S PubidLiteral S SystemLiteral
                // [76] NDataDecl ::= S 'NDATA' S Name [ VC: Notation Declared ]

                if (!entity.IsParsed) // CHANGE 1
                {
                    token = Scanner.Peek();
                    if (token.Type == Scanner.IDENTIFIER)
                    {
                        if (!token.Value.Equals("NDATA"))
                        {
                            throw new DTDParseException(Scanner.GetUriId(),
                                                        "Invalid NData declaration",
                                                        Scanner.GetLineNumber(), Scanner.GetColumn());
                        }
                        // CHANGE 2: Add call to scanner.get.
                        //      This gets "NDATA" IDENTIFIER.
                        token = Scanner.Get();
                        // Get the NDATA "Name" IDENTIFIER.
                        token = Expect(Scanner.IDENTIFIER);
                        // Save the ndata value
                        entity.Ndata = token.Value;
                    }
                }
            }
            else
            {
                throw new DTDParseException(Scanner.GetUriId(),
                                            "Invalid entity definition",
                                            Scanner.GetLineNumber(), Scanner.GetColumn());
            }

            Expect(Scanner.GT);
        }