The following warnings occurred:
Warning [2] Undefined array key "profilelink_plain" - Line: 5 - File: inc/functions_post.php(951) : eval()'d code PHP 8.1.26 (Linux)
File Line Function
/inc/class_error.php 153 errorHandler->error
/inc/functions_post.php(951) : eval()'d code 5 errorHandler->error_callback
/inc/functions_post.php 951 eval
/showthread.php 916 build_postbit
Warning [2] Undefined variable $useravatar - Line: 5 - File: inc/functions_post.php(951) : eval()'d code PHP 8.1.26 (Linux)
File Line Function
/inc/class_error.php 153 errorHandler->error
/inc/functions_post.php(951) : eval()'d code 5 errorHandler->error_callback
/inc/functions_post.php 951 eval
/showthread.php 916 build_postbit
Warning [2] Trying to access array offset on value of type null - Line: 5 - File: inc/functions_post.php(951) : eval()'d code PHP 8.1.26 (Linux)
File Line Function
/inc/class_error.php 153 errorHandler->error
/inc/functions_post.php(951) : eval()'d code 5 errorHandler->error_callback
/inc/functions_post.php 951 eval
/showthread.php 916 build_postbit




Using StAX to Clone an XML Document

1 Replies, 6688 Views

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());}         
  }     
}

Messages In This Thread
Using StAX to Clone an XML Document - by sphere - 05-07-2008, 09:22 AM



Users browsing this thread: 1 Guest(s)