Пример #1
0
exception::exception(
	XML_Parser		parser)
{
	try
	{
		stringstream s;
		
		XML_Error error = XML_GetErrorCode(parser);
		if (error <= XML_ERROR_RESERVED_NAMESPACE_URI)
			s << kXML_Parser_Error_Messages[error];
		else
			s << "Unknown Expat error code";
	
		s << endl
		  << "Parse error at line " << XML_GetCurrentLineNumber(parser)
		  << " column " << XML_GetCurrentColumnNumber(parser)
		  << ":" << endl;
		 
		int offset = 0, size = 0;
		const char* context = XML_GetInputContext(parser, &offset, &size);
		if (context != NULL)
			s << string(context + offset, size) << endl;
	
		m_message = s.str();
	}
	catch (...)
	{
		m_message = "oeps";
	}
}
Пример #2
0
const char* XmlParser::GetInputContext ( int* _offset, int* _pSize )
{
    ex_assert( m_pParser, "m_pParser is not create" );
    return XML_GetInputContext( m_pParser, _offset, _pSize );
}
Пример #3
0
const char * _Expat_XML_GetInputContext(struct ExpatIFace * Self, XML_Parser parser, int * offset, int * size)
{
	return XML_GetInputContext(parser, offset, size);
}
Пример #4
0
const char* XMLParser::GetInputContext(int* pOffset, int* pSize)
{
	assert(m_parser != NULL);
	return XML_GetInputContext(m_parser, pOffset, pSize);
}
Пример #5
0
/*
 * Starts parsing. The XML data being parsed should be set either set as 
 * a buffer in OSCTXT (pctxt->buffer) or read from its stream (pctxt->pStream).
 */
int rtSaxCParse (OSXMLREADER* pReader)
{
   long len;
   enum XML_Status stat = XML_STATUS_OK;
   struct OSRTSTREAM* pStream;
   XMLReaderImpl* readerImpl = (XMLReaderImpl*)(void*)pReader;
   OSCTXT* pctxt;
   OSSAXHandlerBase* pSaxBase;

   if (pReader == 0 || pReader->pctxt == 0 || readerImpl->parser == 0)
      return RTERR_NOTINIT;

   pctxt = pReader->pctxt;
   pStream = pctxt->pStream;
   rtxErrReset (pctxt);
   pSaxBase = (OSSAXHandlerBase*)readerImpl->userData;

   if (pStream == 0) {
      
      /* stream is not set - parse just a buffer */

      stat = XML_Parse (readerImpl->parser, (char*)OSRTBUFPTR(pctxt),
                        (int)pctxt->buffer.size, TRUE);
      return (stat == XML_STATUS_ERROR) ? RTERR_XMLPARSE : 0;
   }
   else { /* read from stream and parse */
      do {
         void* pbuf;
         XML_Bool isFinal;
         
         /* get the buffer to read in */
         pbuf = XML_GetBuffer (readerImpl->parser, XML_BUF_SIZE);

         /* read data to the buffer */
         len = rtxStreamRead (pctxt, (OSOCTET*)pbuf, XML_BUF_SIZE);
         if (len < 0)
            break;
         isFinal = (XML_Bool)(!len);

         /* parse the data in the buffer */
         if ((stat = XML_ParseBuffer (readerImpl->parser, len, isFinal)) == 0) 
            break;

         /* the following code is necessary only if it is necessary to 
          * decode several XML documents consequently from one stream. */
         if (pSaxBase->mState == OS_SAX_FINAL_STATE) {
            /* if parsing is finished, but buffer is not empty we need
             * to find the beginning of the next XML message and set
             * this piece of data as pre-read buffer for BufferedStream.*/
            XML_ParsingStatus status;

            XML_GetParsingStatus(readerImpl->parser, &status);
            if (status.parsing == XML_SUSPENDED) {
               int offset, lenn;

               /* Get buffer pointer, offset and length of remaining data.
                  Note, that patching of Expat is necessary to fix two problems:
                  1) even if parser is stopped by XML_StopParser, it will return
                     error "junk after end-of-document" if buffer is not empty;
                  2) XML_GetInputContext worked only if macro XML_CONTEXT_BYTES
                     was defined. But it could work even without it. */
               const char * _pbuf = 
                  XML_GetInputContext(readerImpl->parser, &offset, &lenn);

               if (offset > 0 && lenn - offset > 0) {
                  int stat = 0;
                  const OSUTF8CHAR* prereadBuf = (const OSUTF8CHAR*)_pbuf + offset;
                  size_t prereadBufLen = (size_t)(lenn - offset), i;

                  /* check, is the buffer just whitespaces or not. If yes,
                     discard it */
                  for (i = 0; i < prereadBufLen; i++) {
                     if (!OS_ISSPACE (prereadBuf[i])) {
                  
                        if (OSRTSTREAM_ID (pctxt) != OSRTSTRMID_DIRECTBUF) {
                           stat = rtxStreamBufferedCreate (pctxt, 
                              OSRTSTRMCM_RESTORE_UNDERLAYING_AFTER_RESET);
                           if (stat < 0) len = stat;
                        }
                        if (stat == 0) {
                           stat = rtxStreamBufferedSetPreReadBuf (pctxt, 
                             (const OSOCTET*)prereadBuf + i, prereadBufLen - i);
                           if (stat < 0) len = stat;
                        }
                        break;
                     }
                  }
               }
               stat = XML_STATUS_OK;
            }
            break;
         }
      } while (len > 0);
   }

   if (len < 0) {
      return LOG_RTERR (pctxt, len);
   }
   else if (stat != XML_STATUS_OK) {
      XML_LChar str[256];
      len = RTERR_XMLPARSE;

      EXML_ErrorString (readerImpl->parser, 
                        XML_GetErrorCode (readerImpl->parser), str, 
                        sizeof(str)/sizeof(str[0]));
      LOG_RTERRNEW (pctxt, len);
      rtxErrAddStrParm (pctxt, LSTRX (pctxt, str));
      return len;
   }

   return 0;
}