Hello.
how can i say to parser that my xml document is encoded with Windows-1251 encoding.....
I have xml document in String, for example
String xmldoc="<?xml version=\ŕ.0\" encoding=\"Windows-1251\"><root>......some letters in windows-1251 encoding</root>" // i thry to use encoding="Windows-1251" and encoding="Cp1251"
next i wrote StringInputStream that reads bytes from String:
public class StringInputStream extends java.io.InputStream { private java.io.StringReader sr; /** Creates a new instance of StringInputStream */ public StringInputStream(String str) { sr=new java.io.StringReader(str); } public int read(){ try{ return sr.read(); }catch(Exception e){ return -1; } } }
next i try to parse document:
DocumentBuilderFactory dbf=DocumentBuilderFactory.newInstance();DocumentBuilder db=dbf.newDocumentBuilder();org.xml.sax.InputSource is=new org.xml.sax.InputSource(new StringInputStream(xmldoc));is.setEncoding("Windows-1251"); // or Cp1251 or i try to comment this lineDocument document=db.parse(is);
and then parser throws Exception "illegal xml character " on position where placed characters in Windows-1251 encoding
is anybody know what is a truble ?