/***** Code de MesExemples.com *******/
/**
* @(#)ExempleXMLStreamReader.java
*
*
* @author
*sakoba(java.mesexemples.com) @version 1.00 2013/7/5
*/
import java.io.File;
import java.io.FileInputStream;
import javax.xml.stream.XMLStreamConstants;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamReader;
public class ExempleXMLStreamReader {
public static void main(String[] args) throws Exception {
File file = new File("test.xml");
XMLInputFactory inputFactory = XMLInputFactory.newInstance();
XMLStreamReader reader = inputFactory.createXMLStreamReader(new
FileInputStream(file));
reader.require(XMLStreamConstants.START_ELEMENT, null, "note");
while (reader.getEventType() == 6)
reader.next();
int eventTypeID = reader.next();
System.out.println("Bienvenu " + reader.getText());
}
}
Code testé avec le fichier XML Suivant
Sakoba
Adams
Rappel
Ne m'oubliez pas ce week-end!