import javax.xml.parsers.*; // JAXP
import javax.xml.transform.*; // JAXP
import javax.xml.transform.dom.DOMSource; // JAXP
import; // JAXP
import org.xml.sax.SAXException;
import org.w3c.dom.Document;

public class RestructureDriver {

  public static void main(String[] args) {
    if (args.length <= 0) {
      System.out.println("Usage: java RestructureDriver URL");
    String url = args[0];
    try {
      // Find a parser
      DocumentBuilderFactory factory 
       = DocumentBuilderFactory.newInstance();
      DocumentBuilder parser = factory.newDocumentBuilder();
      // Read the document
      Document document = parser.parse(url); 
      // Modify the document
      // Write it out again
      TransformerFactory xformFactory 
       = TransformerFactory.newInstance();
      Transformer idTransform = xformFactory.newTransformer();
      Source input = new DOMSource(document);
      Result output = new StreamResult(System.out);
      idTransform.transform(input, output);
    catch (SAXException e) {
      System.out.println(url + " is not well-formed.");
    catch (IOException e) { 
       "Due to an IOException, the parser could not read " + url
    catch (FactoryConfigurationError e) { 
      System.out.println("Could not locate a factory class"); 
    catch (ParserConfigurationException e) { 
      System.out.println("Could not locate a JAXP parser"); 
    catch (TransformerConfigurationException e) { 
      System.out.println("This DOM does not support transforms."); 
    catch (TransformerException e) { 
      System.out.println("Transform failed."); 


Sandeep Joshi
Mathematics, Technology and Programming are my passion. I am a part of Java Ecosystem and through this blog, I contribute to it. I am here to blog about my interests, views and experiences.
I am on Google+ and Facebook.
I feel proud to be listed as a "National Memory Record Holder" in the Limca Book of Records, 2009 and have attempted for an International Memory record in the Guiness Book of Records. I can remember the value of PI upto 10,000 digits after the decimal (3.1415.....). You can contact me on ; I would like to hear from you :)