Java Reference
In-Depth Information
final InputStream is =
StaxIterator.class.getResourceAsStream(db);
try {
//create the reader from the stream
reader = xif.createXMLEventReader(is);
//work with stream and get the type of event
//we're inspecting
while (reader.hasNext()) {
XMLEvent e = reader.nextEvent();
if (e.isStartElement()){
e = e.asStartElement().getAttributeByName(
new QName("sku"));
if (e != null){
out.println(e);
}
}
} //end loop
} catch (XMLStreamException e) {
out.println("Cannot parse: " + e);
}
}
}
Executing the program gives the following output:
sku='123_xaa'
sku='988_yty'
sku='434_asd'
sku='876_pep'
As you can see, the two parsing models are very similar, with slightly different ways of hand-
ling events.
Search WWH ::




Custom Search