Digg StumbleUpon LinkedIn YouTube Flickr Facebook Twitter RSS Reset

Stax XML: Déplacer le curseur à travers les noeud


{filelink=976}

 
import java.io.FileReader;
 
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamReader;
import javax.xml.stream.events.XMLEvent;
 
public class XMLDeplaceCurseur {
  public static void main(String args[]) throws Exception {
    XMLInputFactory xmliFactory = XMLInputFactory.newInstance();
    XMLStreamReader xmlStream = xmliFactory.createXMLStreamReader(new FileReader("test.xml"));
    int eventType;
    while (xmlStream.hasNext())
    	{
      eventType = xmlStream.next();
      switch (eventType) {
      case XMLEvent.START_ELEMENT:
        System.out.println(xmlStream.getName());
        break;
      case XMLEvent.CHARACTERS:
        System.out.println(xmlStream.getText());
        break;
      default:
        break;
      }
    }
  }
}