gnu.xml.util

Class DoParse


public final class DoParse
extends Object

This class provides a driver which may be invoked from the command line to process a document using a SAX2 parser and a specified XML processing pipeline. This facilitates some common types of command line tools, such as parsing an XML document in order test it for well formedness or validity.

The SAX2 XMLReaderFactory should return a SAX2 XML parser which supports both of the standardized extension handlers (for declaration and lexical events). That parser will be used to produce events.

The first parameter to the command gives the name of the document that will be given to that processor. If it is a file name, it is converted to a URL first.

The second parameter describes a simple processing pipeline, and will be used as input to PipelineFactory methods which identify the processing to be done. Examples of such a pipeline include


    nsfix | validate                to validate the input document 
    nsfix | write ( stdout )        to echo the file as XML text
    dom | nsfix | write ( stdout )  parse into DOM, print the result
 

Relatively complex pipelines can be described on the command line, but not all interesting ones will require as little configuration as can be done in that way. Put filters like "nsfix", perhaps followed by "validate", at the front of the pipeline so they can be optimized out if a parser supports those modes natively.

If the parsing is aborted for any reason, the JVM will exit with a failure code. If a validating parse was done then both validation and well formedness errors will cause a failure. A non-validating parse will report failure on well formedness errors.

See Also:
PipelineFactory

Method Summary

static void
main(argv[] )
Command line invoker for this class; pass a filename or URL as the first argument, and a pipeline description as the second.

Methods inherited from class java.lang.Object

clone, equals, extends Object> getClass, finalize, hashCode, notify, notifyAll, toString, wait, wait, wait

Method Details

main

public static void main(argv[] )
            throws IOException
Command line invoker for this class; pass a filename or URL as the first argument, and a pipeline description as the second. Make sure to use filters to condition the input to stages that require it; an nsfix filter will be a common requirement, to restore syntax that SAX2 parsers delete by default. Some conditioning filters may be eliminated by setting parser options. (For example, "nsfix" can set the "namespace-prefixes" feature to a non-default value of "true". In the same way, "validate" can set the "validation" feature to "true".)

DoParse.java -- Copyright (C) 1999,2000,2001 Free Software Foundation, Inc. This file is part of GNU Classpath. GNU Classpath is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. GNU Classpath is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Linking this library statically or dynamically with other modules is making a combined work based on this library. Thus, the terms and conditions of the GNU General Public License cover the whole combination. As a special exception, the copyright holders of this library give you permission to link this library with independent modules to produce an executable, regardless of the license terms of these independent modules, and to copy and distribute the resulting executable under terms of your choice, provided that you also meet, for each linked independent module, the terms and conditions of the license of that module. An independent module is a module which is not derived from or based on this library. If you modify this library, you may extend this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version.