Project

General

Profile

1
package edu.ucsb.nceas.metacat;
2

    
3
import org.w3c.dom.*;
4
import org.xml.sax.*;
5
import org.xml.sax.Parser;
6
import oracle.xml.parser.v2.*;    //Oracle parser
7
//import org.apache.xerces.parsers.*;  //Apache/IBM/Xerces parser
8

    
9
/**
10
 * XMLValidate.java
11
 *         Purpose: A Class that validates XML documents
12
 *   			   This class is uses a specific parser
13
 * 				and calls the GenericXMLValidate class
14
 *                 to do the actual validation
15
 *       Copyright: 2000 Regents of the University of California and the
16
 *                  National Center for Ecological Analysis and Synthesis
17
 *                  April 28, 2000
18
 * 
19
 * @author Dan Higgins
20
 * @version Version 1.0
21
 */
22
public class XMLValidate
23
{
24
    String doc;
25
    SAXParser par;
26
    public boolean validating = false; 
27
    
28
    public XMLValidate( String docname){
29
        doc = docname;
30
        
31
            par = new SAXParser();           // works for both Xerces and Oracle
32
/*            try {   //Xerces
33
            par.setFeature("http://xml.org/sax/features/validation",true);  
34
            }
35
            catch (Exception e) 
36
                {System.out.println("Could not set Validation!!!");
37
                System.exit(0);}
38
                // Xerces end 
39
*/                
40
                
41
                par = new SAXParser();           // works for both Xerces and Oracle
42
                par.setValidationMode(true);     // Oracle
43
            
44
        
45
            
46
            
47
        GenericXMLValidate gxv = new GenericXMLValidate(par);
48
        if (gxv.validate(doc)) {
49
            System.out.println("XML is validated");
50
        }
51
        else {
52
            System.out.print(gxv.returnErrors());    
53
        }
54
    }
55

    
56
    
57
    public static void main(String[] args) {
58
        
59
        if (args.length!=1) {
60
            System.out.println("Usage: java XMLValidate <xmlfile or URL>");
61
            System.exit(0);
62
        }
63
        String doc = args[0];
64
        
65
        
66
        new XMLValidate(doc);
67
    }
68
   
69
    
70
    
71
}
(18-18/29)