Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to determine the encoding of an XML string?

 
James Adams
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there an elegant way to determine the original encoding of some XML? I could parse the first line for the "encoding=", but I wonder if there is another way to go about this which is more elegant. Something like

Document document = saxBuilder.build(xmlFile);
String encoding = document.getEncoding();

(except no such mechanism exists in JDOM)


Thanks in advance for any suggestions!


--James
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In Dom4J (the XML parser of my choice), you'd simply do

document.getXMLEncoding()
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic