To clone an XML document at runtime, use the StAX XMLEventReader and XMLEventWriter classes like this:
//AirWings_order.xml - the original XML in this example
//AirWings_order_clone.xml - the clone of AirWings_order.xml
import javax.xml.stream.*;
import java.io.*;
public class StAXBasicEventWriter_clone{
 public StAXBasicEventWriter_clone(){}
 public static void main(String[] args)
 {
   XMLInputFactory XMLif=null;
   XMLOutputFactory XMLof=null;
   XMLEventReader XMLer=null;
   XMLEventWriter XMLew=null;
     Â
   System.setProperty("javax.xml.stream.XMLInputFactory",
    "com.sun.xml.stream.ZephyrParserFactory"); Â
   System.setProperty("javax.xml.stream.XMLOutputFactory",
    "com.sun.xml.stream.ZephyrWriterFactory");
   //get the XMLInputFactory and XMLOutputFactory objects
   XMLif=XMLInputFactory.newInstance();
   XMLof=XMLOutputFactory.newInstance();
                Â
   //get the XMLEventReader and XMLEventWriter objects
   try{
    XMLer=XMLif.createXMLEventReader    Â
      ("file:///C://Data_Local//xml//docs//",
      new FileReader
      ("C://Data_local//xml//docs//AirWings_order.xml"));
    XMLew=XMLof.createXMLEventWriter(
      new FileWriter
      ("C://Data_local//xml//docs//AirWings_order_clone.xml"));
   }catch(java.io.IOException e)
    {System.out.println(e.getMessage());   Â
   }catch(javax.xml.stream.XMLStreamException e)Â
    {System.out.println(e.getMessage());}
               Â
   //generate the XML document
   try{
    XMLew.add(XMLer);
    //clean up
    XMLew.close();
    XMLer.close();
   }catch(javax.xml.stream.XMLStreamException e)
    {System.out.println(e.getMessage());}    Â
 }  Â
}
//AirWings_order.xml - the original XML in this example
//AirWings_order_clone.xml - the clone of AirWings_order.xml
import javax.xml.stream.*;
import java.io.*;
public class StAXBasicEventWriter_clone{
 public StAXBasicEventWriter_clone(){}
 public static void main(String[] args)
 {
   XMLInputFactory XMLif=null;
   XMLOutputFactory XMLof=null;
   XMLEventReader XMLer=null;
   XMLEventWriter XMLew=null;
     Â
   System.setProperty("javax.xml.stream.XMLInputFactory",
    "com.sun.xml.stream.ZephyrParserFactory"); Â
   System.setProperty("javax.xml.stream.XMLOutputFactory",
    "com.sun.xml.stream.ZephyrWriterFactory");
   //get the XMLInputFactory and XMLOutputFactory objects
   XMLif=XMLInputFactory.newInstance();
   XMLof=XMLOutputFactory.newInstance();
                Â
   //get the XMLEventReader and XMLEventWriter objects
   try{
    XMLer=XMLif.createXMLEventReader    Â
      ("file:///C://Data_Local//xml//docs//",
      new FileReader
      ("C://Data_local//xml//docs//AirWings_order.xml"));
    XMLew=XMLof.createXMLEventWriter(
      new FileWriter
      ("C://Data_local//xml//docs//AirWings_order_clone.xml"));
   }catch(java.io.IOException e)
    {System.out.println(e.getMessage());   Â
   }catch(javax.xml.stream.XMLStreamException e)Â
    {System.out.println(e.getMessage());}
               Â
   //generate the XML document
   try{
    XMLew.add(XMLer);
    //clean up
    XMLew.close();
    XMLer.close();
   }catch(javax.xml.stream.XMLStreamException e)
    {System.out.println(e.getMessage());}    Â
 }  Â
}