You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-dev@xerces.apache.org by "Boris Kolpackov (JIRA)" <xe...@xml.apache.org> on 2009/11/04 11:21:32 UTC

[jira] Updated: (XERCESC-1607) SAX events not fired when they could be

     [ https://issues.apache.org/jira/browse/XERCESC-1607?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Boris Kolpackov updated XERCESC-1607:
-------------------------------------

    Affects Version/s:     (was: 2.7.0)
                           (was: 2.5.0)
                       3.0.1
        Fix Version/s: 3.1.0
             Assignee: Boris Kolpackov

I am interested in fixing this for 3.1.0. Not sure how yet.

> SAX events not fired when they could be
> ---------------------------------------
>
>                 Key: XERCESC-1607
>                 URL: https://issues.apache.org/jira/browse/XERCESC-1607
>             Project: Xerces-C++
>          Issue Type: Bug
>          Components: SAX/SAX2
>    Affects Versions: 3.0.1
>         Environment: Solaris 2.8, 2.10 SPARC - Sun Studio 11
>            Reporter: Gary Hughes
>            Assignee: Boris Kolpackov
>             Fix For: 3.1.0
>
>
> If a BinInputStream returns a valid fragment of XML that should generate SAX parse events it does not necessarily do so before called readBytes again, if the BinInputStream blocks on the subsequent read the XML already returned is not processed as soon as it could be. This is not a problem when reading a file as the XML is eventually processed when EOF is reached however if the XML is being streamed across a socket the BinInputStream never reaches EOF and the XML is not processed.
> Sample program follows, see the comments in BinInputStream::readBytes, error checking etc is largely ignored for brevity.
> #include <xercesc/sax2/SAX2XMLReader.hpp>
> #include <xercesc/sax2/DefaultHandler.hpp>
> #include <xercesc/framework/XMLPScanToken.hpp>
> #include <xercesc/sax2/XMLReaderFactory.hpp>
> #include <xercesc/framework/MemBufInputSource.hpp>
> #include <xercesc/util/XMLUni.hpp>
> #include <iostream>
> #include <algorithm>
> #include <unistd.h>
> class Handler: public XERCES_CPP_NAMESPACE::DefaultHandler
> {
> 	void warning(const XERCES_CPP_NAMESPACE::SAXParseException& exception)
> 	{
> 		std::cout << "WARNING: " << XERCES_CPP_NAMESPACE::XMLString::transcode(exception.getMessage()) << std::endl;	
> 	}
> 	
>     void error(const XERCES_CPP_NAMESPACE::SAXParseException& exception)
>     {
>     	std::cout << "ERROR: " << XERCES_CPP_NAMESPACE::XMLString::transcode(exception.getMessage())  << std::endl;
>     }
>     
>     void fatalError(const XERCES_CPP_NAMESPACE::SAXParseException& exception)
>     {
>     	std::cout << "FATAL ERROR: " << XERCES_CPP_NAMESPACE::XMLString::transcode(exception.getMessage())  << std::endl;
>     }
>  
>     void endElement(const XMLCh* const uri, const XMLCh* const localname, const XMLCh* const qname)
>     {
>     	std::cout << "END ELEMENT" << std::endl;
>     }
>     
>     void startDocument()
>     {
>     	std::cout << "START DOCUMENT" << std::endl;
>     }
>     
>     void startElement(const XMLCh* const uri, const XMLCh* const localname, const XMLCh* const qname, const XERCES_CPP_NAMESPACE::Attributes& attrs)
>     {
>     	std::cout << "START ELEMENT" << std::endl;
>     }
> };
> class BinInputStream : public XERCES_CPP_NAMESPACE::BinInputStream
> {
> public:
> 	bool getIsOpen() const
> 	{
> 		return true;
> 	}
> 	unsigned int curPos() const
> 	{
> 		return 0;
> 	}
> 	
>     unsigned int readBytes(XMLByte* const toFill, 
>     					   const unsigned int maxToRead)
>     {
>     	//
>     	// The first time this is called we return some valid XML which
>     	// should cause the parser to fire events. The second time it is
>     	// called we sleep to simulate a blocking read.
>     	//
>     	// Even though the parser has a valid chunk of XML it does not
>     	// fire any events other than start document.
>     	//
>     	// If the sleep is removed the parser gets EOF and fires the 
>     	// events as expected.
>     	//
>     	static size_t callCount = 0;
>     	
>     	if(callCount > 0)
>     	{
>     		sleep(10000);
>     		return 0;
>     	}
>     	
>     	++callCount;
>     	
>     	std::string xml
>     	(
>     	"<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>"
>     	"<document>"
>     	"	<element/>"
>     	"</document>"
>     	);	
>     	
> 		std::copy(xml.begin(),
> 				  xml.end(),
> 				  toFill);
> 				  
>     	return xml.size();
>     }
> };
> class InputSource : public XERCES_CPP_NAMESPACE::InputSource
> {
> public:
> 	virtual XERCES_CPP_NAMESPACE::BinInputStream* makeStream() const
> 	{
> 		return new BinInputStream;		
> 	}
> };
> int main(int argc, char** argv)
> {
> 	XERCES_CPP_NAMESPACE::XMLPlatformUtils::Initialize();
> 	XERCES_CPP_NAMESPACE::SAX2XMLReader* reader = XERCES_CPP_NAMESPACE::XMLReaderFactory::createXMLReader();
> 	Handler* handler = new Handler;
> 	reader->setContentHandler(handler);
>     reader->setErrorHandler(handler);	
>     
>     XERCES_CPP_NAMESPACE::XMLPScanToken scanToken;
> 	InputSource* inputSource = new InputSource;
> 	
> 	if(!reader->parseFirst(*inputSource, scanToken))
> 		return 1;
> 	
> 	while(reader->parseNext(scanToken));
> 	
> 	return 0;	
> }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: c-dev-unsubscribe@xerces.apache.org
For additional commands, e-mail: c-dev-help@xerces.apache.org