@Test
public void test03() throws XMLStreamException, IOException{
XMLInputFactory xf= XMLInputFactory.newInstance();
InputStream is=TestStax.class.getClassLoader().getResourceAsStream("books.xml");
XMLStreamReader reader=xf.createXMLStreamReader(is);
while(reader.hasNext()){
int type=reader.next();
if(type==XMLStreamConstants.START_ELEMENT){
String name = reader.getName().toString();
if(name.equals("title")){
System.out.print(reader.getElementText()+":");
}
if(name.equals("price")){
System.out.print(reader.getElementText()+"\n");
}
}
}
if(is!=null){
is.close();
}
}
public void test03() throws XMLStreamException, IOException{
XMLInputFactory xf= XMLInputFactory.newInstance();
InputStream is=TestStax.class.getClassLoader().getResourceAsStream("books.xml");
XMLStreamReader reader=xf.createXMLStreamReader(is);
while(reader.hasNext()){
int type=reader.next();
if(type==XMLStreamConstants.START_ELEMENT){
String name = reader.getName().toString();
if(name.equals("title")){
System.out.print(reader.getElementText()+":");
}
if(name.equals("price")){
System.out.print(reader.getElementText()+"\n");
}
}
}
if(is!=null){
is.close();
}
}