Esempio n. 1
0
        Parse(XMLParser *parser, ReadBuffer read, int bufferSize, out XMLError error)
        {
            Debug.Assert(read != null && bufferSize > 0);
            bool     isFinal = false;
            GCHandle bufferHandle;

            while (!isFinal)
            {
                XMLStatus status;
                int       count = read(bufferSize, out bufferHandle);
                try {
                    isFinal = count == 0;
                    IntPtr bufPtr = bufferHandle.AddrOfPinnedObject();
                    status = LibExpat.XMLParse(parser, (byte *)bufPtr, count, isFinal ? 1 : 0);
                }
                finally {
                    if (!isFinal) // if count == 0 then GCHandle was not pinned
                    {
                        bufferHandle.Free();
                    }
                }

                switch (status)
                {
                case XMLStatus.OK:
                    continue;

                case XMLStatus.ERROR:
                    error = LibExpat.XMLGetErrorCode(parser);
#if EXPAT_1_95_8_UP
                    if (error == XMLError.ABORTED)
                    {
                        return(ParseStatus.Aborted);
                    }
#endif
                    return(ParseStatus.FatalError);

#if EXPAT_1_95_8_UP
                case XMLStatus.SUSPENDED:
                    error = XMLError.NONE;
                    return(ParseStatus.Suspended);
#endif
                }
            }
            error = XMLError.NONE;
            return(ParseStatus.Finished);
        }
Esempio n. 2
0
        /* Resumable features */

#if EXPAT_1_95_8_UP
        public bool Suspend()
        {
            CheckNotDisposed();
            bool       result;
            XMLParser *parser = entityContext.XmlParser;

            result = LibExpat.XMLStopParser(parser, XMLBool.TRUE) == XMLStatus.OK;
            if (result)
            {
                entityContext.error = XMLError.NONE;
            }
            else
            {
                entityContext.error = LibExpat.XMLGetErrorCode(parser);
            }
            return(result);
        }
Esempio n. 3
0
        public bool Abort()
        {
            CheckNotDisposed();
            bool       result;
            XMLParser *parser = entityContext.XmlParser;

            // no cleanup here, as we are in the middle of a call-back
            result = LibExpat.XMLStopParser(parser, XMLBool.FALSE) == XMLStatus.OK;
            if (result)
            {
                entityContext.error = XMLError.NONE;
            }
            else
            {
                entityContext.error = LibExpat.XMLGetErrorCode(parser);
            }
            return(result);
        }
Esempio n. 4
0
        ResumeParsingBuffer(XMLParser *parser, ref ParseStatus parseStatus, out XMLError error)
        {
            bool      result = true;
            XMLStatus status = LibExpat.XMLResumeParser(parser);

            switch (status)
            {
            case XMLStatus.OK:
                error = XMLError.NONE;
                XMLParsingStatus pStatus;
                LibExpat.XMLGetParsingStatus(parser, out pStatus);
                if (pStatus.FinalBuffer == XMLBool.FALSE)
                {
                    result = false;
                }
                else
                {
                    parseStatus = ParseStatus.Finished;
                }
                break;

            case XMLStatus.ERROR:
                error = LibExpat.XMLGetErrorCode(parser);
                if (error == XMLError.ABORTED)
                {
                    parseStatus = ParseStatus.Aborted;
                }
                else
                {
                    parseStatus = ParseStatus.FatalError;
                }
                break;

            case XMLStatus.SUSPENDED:
                error       = XMLError.NONE;
                parseStatus = ParseStatus.Suspended;
                break;

            default:
                error = XMLError.NONE;
                break;
            }
            return(result);
        }