Issue
I want to read a xml file in netbeans.I use this code :
DocumentBuilderFactory dbf ; DocumentBuilder db; Document doc = null;
File file = new File(xml_url);
dbf = DocumentBuilderFactory.newInstance();
db = dbf.newDocumentBuilder();
doc = db.parse(file);
and then it gives this error : Byte "239" is not a member of the (7-bit) ASCII character set.
xml header is :
<?xml version="1.0" encoding="us-ascii"?>
How can I fix this? Thanks.
Solution
Your XML file is claiming to be ASCII in the XML header, but it's actually not, since it apparently contains non-ASCII bytes.
Fixes in order of preference:
You should go to whatever/whoever generated the XML file, and get it/them to generate a new correct XML file.
Byte 239 or 0xEF hex, is actually the first byte of the (redundant) UTF-8 byte order mark (BOM)
0xEF 0xBB 0xBF
. I strongly suspect some software incorrectly added it to the beginning of the XML file. Notepad does, for example.If so, remove the byte order mark, it's the first three bytes of the file, just before
<?xml
. If your editor doesn't show it (e.g. i think Notepad doesn't, and Netbeans might also have problems), find another that will.Just opening and resaving the file with an editor that doesn't support UTF-8 BOMs might be enough.
Another way to fix it would be to replace
<?xml version="1.0" encoding="us-ascii"?>
with<?xml version="1.0" encoding="UTF-8"?>
. This will only work if my assumption about the BOM is correct.
Answered By - Christoffer Hammarström
Answer Checked By - Robin (JavaFixing Admin)