Java tutorial
//package com.java2s; import javax.xml.stream.XMLStreamConstants; import javax.xml.stream.XMLStreamReader; public class Main { public static void printStartDocument(XMLStreamReader xmlr) { if (XMLStreamConstants.START_DOCUMENT == xmlr.getEventType()) { System.out.println("<?xml version=\"" + xmlr.getVersion() + "\"" + " encoding=\"" + xmlr.getCharacterEncodingScheme() + "\"" + "?>"); } } }