Bambus
Bambus

Reputation: 1583

XMLEventReader returns STAX

I am using XMLEventReader for parsing big xml files and it works fine in one project but when I import the same class with the same imports in another project it does not parse the xml well and it gives STAX Event.

Below is my code:

    XMLInputFactory factory = XMLInputFactory.newInstance();
    XMLEventReader eventReader = factory.createXMLEventReader(new FileReader(exportedFilePath));

I debugged and inspected the eventReader and in the project where is working is f in property and in the project where does not work there is m.

enter image description here

enter image description here

I can not catch the exception because it is same class and same imports..

Here are the imports:

import javax.xml.stream.XMLEventReader;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamConstants;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.events.Attribute;
import javax.xml.stream.events.Characters;
import javax.xml.stream.events.EndElement;
import javax.xml.stream.events.Namespace;
import javax.xml.stream.events.StartElement;
import javax.xml.stream.events.XMLEvent;

Upvotes: 1

Views: 605

Answers (2)

xmlParser
xmlParser

Reputation: 2041

This should help:

System.setProperty("javax.xml.stream.XMLInputFactory", "com.sun.xml.internal.stream.XMLInputFactoryImpl");

Upvotes: 1

gaborsch
gaborsch

Reputation: 15758

It may be casued by a Classpath problem.

It might be that another class with the same name loaded prior to your class (it may be even within the framework or in the runtime environment) that prevents loading your referred class, for example a different version of your stax parser.

You have three options:

  • Try to find out the version of StAX parser that is present in that environment, and compile yourt code against it

  • Use an own classloader/container for your lib, that will guarantee that the proper version is loaded,

  • try to reorder tha classpath that your lib comes first - though it might corrupt the system elsewhere, so I don't really recommend.

Upvotes: 0

Related Questions