Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

gnu.xml.util
Class DoParse  view DoParse download DoParse.java

java.lang.Object
  extended bygnu.xml.util.DoParse

public final class DoParse
extends java.lang.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 gnu.xml.pipeline.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.


Nested Class Summary
(package private) static class DoParse.MyErrorHandler
           
 
Field Summary
private static int errorCount
           
private static org.xml.sax.SAXParseException fatal
           
private static int fatalCount
           
 
Constructor Summary
private DoParse()
           
 
Method Summary
private static boolean hasValidator(gnu.xml.pipeline.EventConsumer e)
           
static void main(java.lang.String[] argv)
          Command line invoker for this class; pass a filename or URL as the first argument, and a pipeline description as the second.
private static java.lang.String printParseException(java.lang.String label, org.xml.sax.SAXParseException e)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

fatal

private static org.xml.sax.SAXParseException fatal

errorCount

private static int errorCount

fatalCount

private static int fatalCount
Constructor Detail

DoParse

private DoParse()
Method Detail

main

public static void main(java.lang.String[] argv)
                 throws java.io.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".)


hasValidator

private static boolean hasValidator(gnu.xml.pipeline.EventConsumer e)

printParseException

private static java.lang.String printParseException(java.lang.String label,
                                                    org.xml.sax.SAXParseException e)