๐Ÿš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: fr.comp.text.xml
2 messages
2 total messages Started by kvmanoj Sat, 13 Sep 2008 12:27
Unable to handle french characters
#305
Author: kvmanoj
Date: Sat, 13 Sep 2008 12:27
76 lines
3262 bytes
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
Re: Unable to handle french characters
#306
Author: Thomas Harding
Date: Sun, 14 Sep 2008 20:13
19 lines
1626 bytes
Le 13-09-2008, kvmanoj@gmail.com <kvmanoj@gmail.com> a ๏ฟฝcrit๏ฟฝ:
> 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.
[...]

Can't identify formerly the language yu use, but you'd better to write
into fr.comp.lang.(java|c|whatever), as this group is almost died.

(je renvoie l'utilisateur vers fr.comp.lang.*)

-- 
=== The BOFH Excuse Server ===
Your excuse is: You can tune a file system, but you can't tune a fish
(from most tunefs man pages)
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads