FileDocCategorySizeDatePackage
SerializerTest.javaAPI DocExample3735Thu Aug 16 16:49:40 BST 2001javaxml2

SerializerTest

public class SerializerTest extends Object

SerializerTest simply provides a test case for the {@link DOMSerializer} class, by building a DOM tree from a supplied filename and then serializing that tree back out.

Fields Summary
Constructors Summary
Methods Summary
public static voidmain(java.lang.String[] args)

Provide a static entry point for testing the DOMSerializer.

        if (args.length != 2) {
            System.out.println(
                "Usage: java javaxml2.SerializerTest " +
                "[XML document to read] " +
                "[filename to write out to]");
            System.exit(0);
        }

        try {
            SerializerTest tester = new SerializerTest();
            tester.test(args[0], args[1]);
        } catch (Exception e) {
            e.printStackTrace();
        }
    
public voidtest(java.lang.String xmlDocument, java.lang.String outputFilename)

This creates a DOM tree from the supplied XML filename, and then serializes the tree to the specified file.

param
xmlDocument filename of XML input document.
param
outputFilename filename of output document.


        File outputFile = new File(outputFilename);
        DOMParser parser = new DOMParser();

        // Get the DOM tree as a Document object
        parser.parse(xmlDocument);
        Document doc = parser.getDocument();

        // Serialize
        DOMSerializer serializer = new DOMSerializer();
        serializer.serialize(doc, new File(outputFilename));