Exemplo n.º 1
0
        public ParseStatus Resume()
        {
            CheckNotDisposed();
            ParseStatus status;

            for (; ;)
            {
                XMLParser *parser = entityContext.XmlParser;
                try {
                    status = ExpatUtils.ResumeParsing(parser, entityContext.Read, out entityContext.error);
                    isDone = status != ParseStatus.Suspended;
                }
                catch {
                    isDone = true;
                    throw;
                }
                if (status == ParseStatus.Finished && entityContext.Parent != null)
                {
                    PopChildEntityParseContext(); // return to parsing parent entity
                }
                else
                {
                    break;
                }
            }
            return(status);
        }
Exemplo n.º 2
0
        /* Main Parse method */

        public ParseStatus Parse(ReadBuffer read)
        {
            CheckNotParsing();
            XMLParser *parser;

            if (isDone)
            {
                parser = ResetParser();
                isDone = false;
            }
            else
            {
                parser = entityContext.XmlParser;
            }
            entityContext.Init(read);
            ParseStatus status;

            try {
                status = ExpatUtils.Parse(parser, read, out entityContext.error);
                isDone = status != ParseStatus.Suspended;
            }
            catch {
                isDone = true;
                throw;
            }
            return(status);
        }
Exemplo n.º 3
0
        ExternalEntityRefHandlerImpl(XMLParser *parser,
                                     char *context,
                                     char *baseUri,
                                     char *systemId,
                                     char *publicId)
        {
            int result = (int)XMLStatus.OK;

            GCHandle parserHandle = (GCHandle)LibExpat.XMLGetUserData(parser);
            X        expatParser  = (X)parserHandle.Target;

            E      newEntityContext = expatParser.freeEntityContext; // should always be != null
            string encoding;

            try {
                if (!newEntityContext.Open(context, baseUri, systemId, publicId, out encoding))
                {
                    return(result);
                }
            }
            catch (Exception e) {
                expatParser.error = e;
                result            = (int)XMLStatus.ERROR;
                return(result);
            }

            expatParser.PushChildEntityParseContext(parser, context, encoding);

            ParseStatus status = ExpatUtils.Parse(
                newEntityContext.XmlParser, newEntityContext.Read, out newEntityContext.error);

            switch (status)
            {
            case ParseStatus.Finished:
                expatParser.PopChildEntityParseContext();
                break;

            case ParseStatus.Suspended:
                // must suspend parent parser as well - don't check return value
                LibExpat.XMLStopParser(parser, XMLBool.TRUE);
                break;

            case ParseStatus.FatalError:
                result = (int)XMLStatus.ERROR;
                break;

            case ParseStatus.Aborted:
                // must abort parent parser as well - don't check return value
                LibExpat.XMLStopParser(parser, XMLBool.FALSE);
                break;
            }
            return(result);
        }
Exemplo n.º 4
0
        internal unsafe Stream Resolve(char *baseUri, char *systemId, char *publicId, out string encoding)
        {
            const char NullChar = (char)0;
            Stream     stream   = null;
            string     sysIdStr = null;

            encoding = null;

            // normalize empty string
            if (systemId != null && *systemId != NullChar)
            {
                sysIdStr = new string(systemId);
            }
            // do we have a foreign DTD?
            if (sysIdStr == null)
            {
                if (OnResolveForeignDtd != null)
                {
                    stream = OnResolveForeignDtd(ref encoding);
                }
            }
            else
            {
                string baseUriStr = null;
                if (baseUri != null && *baseUri != NullChar)
                {
                    baseUriStr = new string(baseUri);
                }
                Uri bsUri = null;
                if (baseUriStr != null)
                {
                    bsUri = new Uri(baseUriStr);
                }
                if (OnResolveExternalId != null)
                {
                    string pubIdStr = null;
                    // normalize empty string
                    if (publicId != null && *publicId != NullChar)
                    {
                        pubIdStr = new string(publicId);
                    }
                    stream = OnResolveExternalId(bsUri, sysIdStr, pubIdStr, ref encoding);
                }
                else
                {
                    stream = ExpatUtils.UriToStream(bsUri, sysIdStr, UriTimeout, IgnoreTimeoutError);
                }
            }
            return(stream);
        }