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 pabna01 <pa...@ca.com> on 2010/11/29 12:06:44 UTC

Having a SAX2 parser parsing problem during the code migration from Xerces 2.8 to 3.1

Hi,

I am migrating from xerces 2.8 to latest version of xerces 3.1.

I was using SAX2XMLReader in the following way.

class XercesRequestParser : public DefaultHandler
{
             XercesRequestParser();
	~XercesRequestParser();

             long parseRequest(ispData *ispdata);
	void warning(const SAXParseException& e);
	void error(const SAXParseException& e);
	void fatalError(const SAXParseException& e);
	void resetErrors();

	/* Callback registered to Xerces SAX Parser */
	void startElement(const XMLCh *const uri, const XMLCh *const localname,
					const XMLCh *const qname, const Attributes &attrs);
	void endElement(const XMLCh *const uri, const XMLCh *const localname,
					const XMLCh *const qname);
             void endDocument();
             void characters(const XMLCh* const chars, const unsigned int
length);
             void ignorableWhitespace(const XMLCh* const chars, const
unsigned int length);

private:
             ..................
};


I am Creating the SAX2XMLReader as below inside the cpp file.

             SAX2XMLReader		*parser;		// our request parser object
	MemBufInputSource	*inputsource;	// input source for xml request

             try
	{
		// create parser and set up default values
		parser = XMLReaderFactory::createXMLReader();

		parser->setFeature(XMLUni::fgSAX2CoreValidation, false);
		parser->setFeature(XMLUni::fgSAX2CoreNameSpaces, true);
		
                          // set error handler to ourself
   		parser->setErrorHandler(this);
		parser->setContentHandler(this);
	}
	catch (...)
	{
		printf("XercesRequestParser::Parse(): exception setting up parser\n");
		return 404;
	}

	try
	{
		inputsource = new MemBufInputSource((const XMLByte*)data->GetXmlRequest(),		
strlen(m_ispdata->GetXmlRequest()),			// length
		"Data m_xmlrequest",                  			// id
		false);										}
	catch (...)
	{
		printf("XercesRequestParser::Parse(ispdata): exception setting up
inputsource\n");
		delete parser;
		return 404;
	}
             
             bool errorsOccured = false;
             try
             {
                       parser->parse(*inputsource);
             }
             catch (const XMLException &e)
             {
	           printf("XercesRequestParser::Parse(ispdata): An error occured
during parsing [%s]\n",
				Char(e.getMessage()));
                         errorsOccured = true;
             }
             catch (...)
             {
		printf( "XercesRequestParser::Parse(ispdata): Unknown error occured during
parsing\n");
                          errorsOccured = true;
             }

             delete parser;
	delete inputsource;

	


Suppose If the XML data  is as follows

<Sample Version="2.0">data</Sample>

The registered callbacks startElement and endElement are called during the
processing when it encounters "Sample" Element tag.But "characters" method
is not called when the xerces encounters the "Sample" element value  "data".

I am unable to get the value inside the Xml tag ie. in this case it is
"data".

This is not the case with usage of 2.8 but facing problem when I am using
Xercces 3.1.

Do I need to add or make any changes to get this problem solved in my code.
Please help me.

Thanks,
Rao.



-- 
View this message in context: http://old.nabble.com/Having-a-SAX2-parser-parsing-problem-during-the-code-migration-from-Xerces-2.8-to-3.1-tp30329371p30329371.html
Sent from the Xerces - C - Dev mailing list archive at Nabble.com.


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


Re: Having a SAX2 parser parsing problem during the code migration from Xerces 2.8 to 3.1

Posted by pabna01 <pa...@ca.com>.
Hi  Vitaly,

Thanks very much.I was doing something wrong inside the code.Changing the
prototype as you suggested working.

Thanks
Rao.

-- 
View this message in context: http://old.nabble.com/Having-a-SAX2-parser-parsing-problem-during-the-code-migration-from-Xerces-2.8-to-3.1-tp30329371p30337014.html
Sent from the Xerces - C - Dev mailing list archive at Nabble.com.


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


Re: Having a SAX2 parser parsing problem during the code migration from Xerces 2.8 to 3.1

Posted by pabna01 <pa...@ca.com>.

Hi  Vitaly,

  No Luck .changing the prototype as suggested didnt resolve the
problem.Please suggest me If there is anything else I am doing wrong in the
code.

Thanks,
Rao.
-- 
View this message in context: http://old.nabble.com/Having-a-SAX2-parser-parsing-problem-during-the-code-migration-from-Xerces-2.8-to-3.1-tp30329371p30330181.html
Sent from the Xerces - C - Dev mailing list archive at Nabble.com.


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


Re: Having a SAX2 parser parsing problem during the code migration from Xerces 2.8 to 3.1

Posted by Vitaly Prapirny <ma...@mebius.net>.
Hi,

pabna01 wrote:
>               void characters(const XMLCh* const chars, const unsigned int
> length);

> The registered callbacks startElement and endElement are called during the
> processing when it encounters "Sample" Element tag.But "characters" method
> is not called when the xerces encounters the "Sample" element value  "data".

Could you try this version:
      void characters(const XMLCh* const chars, const XMLSize_t length);

Good luck!
	Vitaly

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