This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Soft Skills: The software developer's life manual and have John Sonmez on-line!
See this thread for details.
Win a copy of Soft Skills: The software developer's life manual this week in the Jobs Discussion forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to determine the encoding of an XML string?

 
James Adams
Ranch Hand
Posts: 188
  • 0
  • 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
  • 0
  • 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()
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic