1

While I am processing XML file, the Stax parser encountered the following line:

<node id="281224530" lat="48.8975614" lon="8.7055191" version="8" timestamp="2015-06-07T22:47:39Z" changeset="31801740" uid="272351" user="Krte�?ek">

and as you see there is a strange character at the end of the line, and when the parser reaches that line the program stops and gives me the following error:

Exception in thread "main" javax.xml.stream.XMLStreamException: ParseError  
at [row,col]:[338019,145]

Message: Ungültiges Byte 2 von 2-Byte-UTF-8-Sequenz.
at com.sun.org.apache.xerces.internal.impl.XMLStreamReaderImpl.next(Unknown 
Source)
at com.example.Main.main(Main.java:46)

Is there any thing I should change in the settings of Eclipse to avoid that error?

Update

code:

XMLInputFactory factory = XMLInputFactory.newInstance();
        XMLStreamReader parser = null;
        try {
            parser = factory.createXMLStreamReader(in);
        } catch (XMLStreamException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            Log.d(TAG, "newParser",
                    "e/createXMLStreamReader: " + e.getMessage());
        }
Jiri Tousek
  • 11,964
  • 5
  • 27
  • 41
user2121
  • 7,091
  • 17
  • 63
  • 138

3 Answers3

1

It is not about eclipse, but it is about encoding of your file. There are two cases:

1) file is corrupted, i.e. it contains incorrect symbols, not from defined encoding

2) file is not in utf-8 encoding and it is defined in xml header. So you should check, that you are reading file contents appropriately.

Andremoniy
  • 32,711
  • 17
  • 122
  • 230
0

Read XML using UTF8 format.

File file = new File("c:\\your-file.xml");
InputStream inputStream= new FileInputStream(file);
Reader reader = new InputStreamReader(inputStream,StandardCharsets.UTF_8);

see the encoding of your file from comment: from reateXMLEventReader(InputStream stream, String encoding)

parser = factory.createXMLStreamReader(in, StandardCharsets.UTF_8); //if its utf-8
Sumit Singh
  • 24,095
  • 8
  • 74
  • 100
0

If you edited and saved your XML file in eclipse, this can be a problem in case your eclipse is not configured to use UTF-8. Check this question: How to support UTF-8 encoding in Eclipse

Otherwise you probably don't need to do anything about your code. You just need a correctly UTF-8-encoded content.

Community
  • 1
  • 1
nolexa
  • 2,312
  • 1
  • 18
  • 19