You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by dl...@apache.org on 2001/11/05 20:28:49 UTC

cvs commit: xml-xalan/java/samples/Validate ValidateXMLInput.java

dleslie     01/11/05 11:28:49

  Modified:    java/samples/Validate ValidateXMLInput.java
  Log:
  Simplified, now that Xalan is no longer preventing XMLReader
  from passes warnings and errors to an error handler during a
  transformation (fix submitted by Scott Boag).
  
  Revision  Changes    Path
  1.2       +14 -25    xml-xalan/java/samples/Validate/ValidateXMLInput.java
  
  Index: ValidateXMLInput.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/samples/Validate/ValidateXMLInput.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ValidateXMLInput.java	2001/11/02 21:57:06	1.1
  +++ ValidateXMLInput.java	2001/11/05 19:28:49	1.2
  @@ -73,11 +73,11 @@
   
   /**
    * Validate the XML input by using SAXParserFactory to turn on namespace awareness and 
  - * validation, and a SAX XMLReader to parse the input and report problems to a very
  - * simple error handler. 
  + * validation, and a SAX XMLReader to parse the input and report problems to an error 
  + * handler.
    * 
  - * This sample uses birds.xml with an internal doctype declaration. As shipped, birds.xml
  - * contains an element that violates the doctype.
  + * This sample uses birds.xml with an internal DOCTYPE declaration. As shipped, birds.xml
  + * contains an element that violates the declared document type.
    */
   public class ValidateXMLInput
   {
  @@ -102,7 +102,12 @@
         pfactory.setValidating(true);
         // Get an XMLReader.
         XMLReader reader = pfactory.newSAXParser().getXMLReader();
  -      
  +  
  +      // Instantiate an error handler (see the Handler inner class below) that will report any
  +      // errors or warnings that occur as the XMLReader is parsing the XML input.
  +      Handler handler = new Handler();
  +      reader.setErrorHandler(handler);
  +  
         // Standard way of creating a transformer from a URL.
         Transformer t = tfactory.newTransformer(
           new StreamSource("birds.xsl"));
  @@ -111,31 +116,15 @@
         SAXSource source = new SAXSource(reader,
           new InputSource("birds.xml"));
         
  -      try
  -      {
  -        // Transform to a file.
  -        t.transform(source, new StreamResult("birds.out"));
  -      }
  -      catch(TransformerException te)
  -      {
  -        // The operation failed, so parse the entire XML input to get a complete listing of 
  -        // warnings and errors from the Handler inner class (see below).
  -        Handler handler = new Handler();
  -        reader.setErrorHandler(handler);
  -        reader.parse("birds.xml");
  -        
  -        // Note: If you are satisifed with reporting just the first exception, you can
  -        // eliminate the preceding 3 statements and Handler inner class, and then report
  -        // the first TransformerException as follows:
  -        // System.out.println(te.getMessage());
  -      }
  -      System.out.println("Done!");
  +      // Transform to a file.
  +      t.transform(source, new StreamResult("birds.out"));
  +      System.out.println("=====Done=====");
       }
       else
         System.out.println("tfactory does not support SAX features!");
     }
   
  -  // Catch any errors or warnings from the XMLReader parse operation.
  +  // Catch any errors or warnings from the XMLReader.
     class Handler extends DefaultHandler
     {
       public void warning (SAXParseException spe)
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-cvs-help@xml.apache.org