Meaningless Drivel is fun!
The moose likes XML and Related Technologies and the fly likes about charset on XML Dom Object Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "about charset on XML Dom Object" Watch "about charset on XML Dom Object" New topic

about charset on XML Dom Object

chao cai
Ranch Hand

Joined: May 26, 2005
Posts: 154
why some XML String with the encoding statement(encoding="GB2312") parse by dom object SUN JDK1.4 provided will get wrong characters,but the same XML String with the encoding statement(encoding="GBK") everything is OK?
By the way,the Dom Object got the XML String by String inputstream.

StringBufferInputStream instream = new StringBufferInputStream(XML_STRING);
try {
DocumentBuilderFactory domfactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dombuilder = domfactory.newDocumentBuilder();
doc = dombuilder.parse(instream);
} catch (Exception e) {
throw new ParseException(e.getMessage());

Also, the DOM object got the XML String directly from the file,everything is ok, in this case you can use any encodings.

SCEA<br />SCJP 1.2<br />SCBCD<br />MCSD<br />IBM Certified Specialist RUP v2003<br />IBM Certified Solution Designer OOAD vUML2<br /> <br />Phone Number:86-010-82776427
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11778

Moved to XML and Related Technologies.

The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
I agree. Here's the link:
subject: about charset on XML Dom Object
It's not a secret anymore!