Hello,
I just would like use XMLStreamReader (going on with reader.next() in a loop) to read an xml BUT I want to skip whitespace, '\n', '\t' and similars.
I thought the solution was XMLStreamFilter ed and I coded it (maybe in a wrong way either I didn't understand how to use it):
Something wrong happen: accept() is called, return true, and the problem exit printing 'null' on the console. none exceptions.
I just would like use XMLStreamReader (going on with reader.next() in a loop) to read an xml BUT I want to skip whitespace, '\n', '\t' and similars.
I thought the solution was XMLStreamFilter ed and I coded it (maybe in a wrong way either I didn't understand how to use it):
Code:
//main
FileInputStream source = null;
XMLInputFactory inputFactory = null;
inputFactory.createXMLStreamReader(source);
source = new FileInputStream("myfile.xml");
inputFactory = XMLInputFactory.newFactory();
XMLStreamReader reader = inputFactory.createFilteredReader(inputFactory.createXMLStreamReader(source), new MyStreamFilter() );
while ( reader.hasNext() ) {
int event = reader.next();
}
//MyStreamFilter.java
public class MyStreamFilter implements javax.xml.stream.StreamFilter {
public boolean accept(XMLStreamReader reader) {
if (reader.isWhiteSpace() ||
(reader.hasText() && ( reader.getText() == "\n" || reader.getText() == "\t")) ) {
return false;
}
return true;
}
}
Comment