FileDocCategorySizeDatePackage
TestDOMParsing.javaAPI DocExample3969Wed Sep 19 09:16:10 BST 2001javaxml2

TestDOMParsing

public class TestDOMParsing extends Object

TestDomParsing is a simple class that demonstrates how JAXP can be used for working with the DOM (Document Object model).

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

Provide a static entry point.

        try {
            if (args.length != 1) {
                System.err.println (
                    "Usage: java TestDOMParsing [filename]");
                System.exit(1);
            }

            // Get Document Builder Factory
            DocumentBuilderFactory factory = 
                DocumentBuilderFactory.newInstance();

            // Turn on validation, and turn off namespaces
            factory.setValidating(true);
            factory.setNamespaceAware(false);

            DocumentBuilder builder = factory.newDocumentBuilder();
            Document doc = builder.parse(new File(args[0]));

            // Serialize the DOM tree
            DOMSerializer serializer = new DOMSerializer();
            serializer.serialize(doc, System.out);

        } catch (ParserConfigurationException e) {
            System.out.println("The underlying parser does not " +
                "support the requested features.");
        } catch (FactoryConfigurationError e) {
            System.out.println("Error occurred obtaining Document " +
                "Builder Factory.");
        } catch (Exception e) {
            e.printStackTrace();
        }