nntp2http.com
Posting
Suche
Optionen
Hilfe & Kontakt

Unable to handle french characters

Von: kvmanoj@gmail.com [Profil]
Datum: 13.09.2008 14:27
Message-ID: <b8235aa2-01d4-46e1-beb7-ac6e4460da69@p10g2000prf.googlegroups.com>
Newsgroup: fr.comp.text.xml
Hi,

I have a problem in reading french characters using SAX2XMLReader.
my code works fine with xml file which has all english characters.

but if i have french data in the xml file, SAX2XMLReader->parse( )
fails reporting fatal error.

Is there anything specific should i do using setFeature( ) to
handle non-english characters?

here is the sample code.

bool XMLTree::ParseUsingSAX2()
{
try
{
// Perform per-process parser initialization. The default locale
is "en_US".
XMLPlatformUtils::Initialize();
}
catch (const XMLException& toCatch)
{
// Transcodes a string to native code-page.
char* t_message = XMLString::transcode(toCatch.getMessage());
XMLString::release( &t_message );
return false;
}

SAX2XMLReader* t_parser = XMLReaderFactory::createXMLReader();
if( !t_parser )
{
return false;
}

// Report all validation errors.  If this feature is set to true,
// the document must specify a grammar. If this feature is set to
false
// and document specifies a grammar, that grammar might be parsed
but no
// validation of the document contents will be performed.
t_parser->setFeature(XMLUni::fgSAX2CoreValidation, false);
// Perform Namespace processing. If the validation feature is set to
true, then the document
// must contain a grammar that supports the use of namespaces.
t_parser->setFeature(XMLUni::fgSAX2CoreNameSpaces, true);   //
optional

mDefaultHandler = new  (nothrow) MySAX2Handler(this);
if( !mDefaultHandler )
{
delete t_parser;
return false;
}

// Register a document event handler.
t_parser->setContentHandler( mDefaultHandler );
// Register an error event handler.
t_parser->setErrorHandler( mDefaultHandler );

try
{
t_parser->parse( mFileName.c_str() );
if ( t_parser->getErrorCount() > 0 )
{
delete t_parser;
return false;
}
}
}

I registered call backs for content, warning, error, fatal error
and end document using SAX2XMLReader.

Thanks,
Manoj

[ Auf dieses Posting antworten ]