java - How to read same XML file more times using XMLStreamReader -
i read xml file in 3 phases , in each phase, interested in different elements, based on input parameters.
what best approach read 1 xml file more times using xmlstreamreader?
xmlinputfactory = xmlinputfactory.newinstance(); try { xmlstreamreader streamreader xmlinputfactory.createxmlstreamreader(inputstream); try { while (streamreader .hasnext()) {
where inputstream fileinputstream instance
at moment, either stream closed exception or streamreader.hasnext() false when start second phase reading.
load file memory , use bytearrayinputstream
file f = ...; int len = (int)f.length(); // careful: if life on 4 gigs won't work byte myxml[] = new byte[]; fileinputstream fis = new fileinputstream(f); int read = fis.read(f); // not guarenteed read bytes, in experience, reads bytes if (read != len) throw runtimeexcption("didn't read everything"); // can create many xmlstreamreaders want try { xmlstreamreader streamreader xmlinputfactory.createxmlstreamreader(new bytearrayinputstream(buf));
Comments
Post a Comment