@Test
public void test02() 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("book")){
System.out.println(reader.getAttributeName(0)+":"+reader.getAttributeValue(0));
}
}
}
if(is!=null){
is.close();
}
public void test02() 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("book")){
System.out.println(reader.getAttributeName(0)+":"+reader.getAttributeValue(0));
}
}
}
if(is!=null){
is.close();
}
}
获取节点下的属性