Java XML: Exemple d’utilisation de XMLInputFactory

Author:

Java XML: Exemple d'utilisation de XMLInputFactory
{filelink=8747}

/***** Code de MesExemples.com *******/
 import java.io.FileInputStream;import javax.xml.stream.XMLEventReader;import javax.xml.stream.XMLEventWriter;import javax.xml.stream.XMLInputFactory;import javax.xml.stream.XMLOutputFactory;import javax.xml.stream.XMLResolver;import javax.xml.stream.XMLStreamException;public class 
    ExempleXMLInputFactory
 {  public static void main(String[] args) throws Exception {    XMLInputFactory inputFactory = XMLInputFactory.newInstance();    inputFactory.setXMLResolver(new XMLResolver() {      public Object resolveEntity(String publicID, String systemID, String baseURI, String namespace)          throws XMLStreamException {        System.out.println(systemID);        return null;      }    });    XMLEventReader reader = inputFactory.createXMLEventReader(new FileInputStream(        "test.xml"));    XMLEventWriter writer = XMLOutputFactory.newInstance().createXMLEventWriter(System.out);    writer.add(reader);    writer.flush();  }} 

Code testé avec le fichier XML Suivant




	Sakoba
	Adams
	Rappel
	Ne m'oubliez pas ce week-end!

Leave a Reply

Your email address will not be published. Required fields are marked *