This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "about charset on XML Dom Object" Watch "about charset on XML Dom Object" New topic
Author

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: 11404
    
  81

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
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: about charset on XML Dom Object
 
Similar Threads
Creating JDOM Document from a String
problem parsing xml string using dom parser
can i use DOM.. to see if xml is well formed
? - Is there a way to validate 1 XML record at a time, using the SAX or other parser!
problem parsing xml string using dom parser