Project

General

Profile

1
/**
2
 *      Name: XMLValidate.java
3
 *   Purpose: A Class that validates XML documents
4
 *            This class is uses a specific parser
5
 *            and calls the GenericXMLValidate class
6
 *            to do the actual validation
7
 * Copyright: 2000 Regents of the University of California and the
8
 *            National Center for Ecological Analysis and Synthesis
9
 *   Authors: Dan Higgins 
10
 * 
11
 *   Version: '$Id: XMLValidate.java 168 2000-06-16 03:20:41Z jones $'
12
 */
13
package edu.ucsb.nceas.metacat;
14

    
15
import org.w3c.dom.*;
16
import org.xml.sax.*;
17
import org.xml.sax.Parser;
18
import oracle.xml.parser.v2.*;    //Oracle parser
19
//import org.apache.xerces.parsers.*;  //Apache/IBM/Xerces parser
20

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

    
68
    
69
    public static void main(String[] args) {
70
        
71
        if (args.length!=1) {
72
            System.out.println("Usage: java XMLValidate <xmlfile or URL>");
73
            System.exit(0);
74
        }
75
        String doc = args[0];
76
        
77
        
78
        new XMLValidate(doc);
79
    }
80
   
81
    
82
    
83
}
(20-20/20)