FileDocCategorySizeDatePackage
ElementChanger.javaAPI DocExample4229Sat Sep 01 16:02:50 BST 2001javaxml2

ElementChanger

public class ElementChanger extends Object
ElementChanger demonstrates how custom JDOM subclasses can be used when loading an XML document. To demonstrate, a file is read in using custom subclasses, and then written out. The effect of the custom subclasses is then visible on the output document.

Fields Summary
Constructors Summary
Methods Summary
public voidchange(java.lang.String inputFilename, java.lang.String outputFilename)

This method loads the supplied XML document, uses the custom {@link ORAElement} via the {@link CustomJDOMFactory}, and then writes out the customized document to the supplied output file.

param
inputFilename the file to load the XML from.
param
outputFilename the file to write XML to.
throws
IOException - when read/write errors occur.
throws
JDOMException - when problems with JDOM occur.


        // Create builder and set up factory
        SAXBuilder builder = new SAXBuilder();
        JDOMFactory factory = new CustomJDOMFactory();
        builder.setFactory(factory);
        
        // Build document 
        Document doc = builder.build(inputFilename);

        // Output document
        XMLOutputter outputter = new XMLOutputter(); 
        outputter.output(doc, new FileWriter(new File(outputFilename)));
    
public static voidmain(java.lang.String[] args)

Provide a static entry point for testing.

        if (args.length != 2) {
            System.out.println("Usage: javaxml2.ElementChanger " +
                "[XML Input Filename] [XML Output Filename]");
            return;
        }

        try {
            ElementChanger changer = new ElementChanger();
            changer.change(args[0], args[1]);
        } catch (Exception e) {
            e.printStackTrace();
        }