🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: fr.comp.text.xml
Article #305

Unable to handle french characters

#305
From: 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
Technical Details
Message-ID: <b8235aa2-01d4-46e1-beb7-ac6e4460da69@p10g2000prf.googlegroups.com>
Path: arc1-ca.pugleaf.net!g2news2.google.com!postnews.google.com!p10g2000prf.googlegroups.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Thread: 114f60,b1bbc34013c4746f,start
X-Google-Attributes: gid114f60,domainid0,public,usenet
X-Google-Language: ENGLISH,ASCII-7-bit
Path: arc1-ca.pugleaf.net!g2news2.google.com!postnews.google.com!p10g2000prf.googlegroups.com!not-for-mail
From: kvmanoj@gmail.com
Newsgroups: fr.comp.text.xml
Subject: Unable to handle french characters
Date: Sat, 13 Sep 2008 05:27:40 -0700 (PDT)
Organization: http://groups.google.com
Lines: 76
Message-ID: <b8235aa2-01d4-46e1-beb7-ac6e4460da69@p10g2000prf.googlegroups.com>
NNTP-Posting-Host: 124.123.174.152
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
X-Trace: posting.google.com 1221308861 14552 127.0.0.1 (13 Sep 2008 12:27:41 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Sat, 13 Sep 2008 12:27:41 +0000 (UTC)
Complaints-To: groups-abuse@google.com
Injection-Info: p10g2000prf.googlegroups.com; posting-host=124.123.174.152; 
 posting-account=nMJ1WQoAAAA4db8k-6NHhfip5mMaRYf6
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.16) 
 Gecko/20080702 Firefox/2.0.0.16,gzip(gfe),gzip(gfe)