• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

Handling Special Characters

 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have input XML with the encodings UTF-8 and ISO-8859-1 containing special characters.
So how to handle this encoding in my application?

Pl guide me to solve this problem.

Thanks
Manish
 
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Manish

When you instantiate the StreamReader/Writer you can specify the character set to be used. Check out the Charset class for more info.

For example:


Cheers
Steve
 
Marshal
Posts: 26912
82
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Or better still, don't use a Reader at all. When you parse the document, make sure you give the parser an InputStream (or a File or a URL). XML parsers are designed to discover an XML document's encoding themselves, so don't try to "help" your parser.

Of course if your document was written by bozo software, and it doesn't correctly state its encoding, then you won't be able to parse it. But in that case you should ask for a well-formed document as a replacement.
 
Steve McCann
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Of course if your document was written by bozo software, and it doesn't correctly state its encoding...


Got it in one.
[ June 14, 2007: Message edited by: Steve McCann ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic