Пример #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);
        }