samedi 9 mai 2015

Why my XMLEventWriter don't write anything?

I am trying to make a filter but my XMLStreamWriter object seems not to write anything, even to System.out.

public static void main(String... args) throws FileNotFoundException, XMLStreamException {
    //FileOutputStream outputFile = new FileOutputStream("C:\\Users\\Badescu\\Desktop\\outFile.xml");
    XMLOutputFactory outputFactory =  XMLOutputFactory.newInstance();
    XMLEventWriter eventWriter = outputFactory.createXMLEventWriter(System.out);
    //eventWriter = new IndentingXMLEventWriter(eventWriter); // error "IndentingXMLEventWriter cannot be resolved to a type"
    XMLEventFactory eventFactory = XMLEventFactory.newInstance();
    eventWriter.add(eventFactory.createStartDocument());
    eventWriter.add(eventFactory.createStartElement("", "", "a"));
    eventWriter.add(eventFactory.createStartElement("", "", "b"));
    eventWriter.add(eventFactory.createEndElement("", "", "b"));
    eventWriter.add(eventFactory.createEndElement("", "", "a"));
    eventWriter.add(eventFactory.createEndDocument());
}

If I uncomment the line where I've declared the "outputFile" it creates the file but it is empty. The filter that I want to create is the one that can be applied to my previvous question: "Extract specific elements from an input file and write them to an output file using StAX"

Aucun commentaire:

Enregistrer un commentaire