Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

problem with xml encoding

843834Sep 30 2004 — edited Oct 1 2004
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=\&#341;.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 &#x1f" on position where placed characters in Windows-1251 encoding

is anybody know what is a truble ?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 29 2004
Added on Sep 30 2004
3 comments
220 views