Project

General

Profile

1 66 higgins
import org.w3c.dom.*;
2
import org.xml.sax.*;
3
import org.xml.sax.Parser;
4
import oracle.xml.parser.v2.*;    //Oracle parser
5
//import org.apache.xerces.parsers.*;  //Apache/IBM/Xerces parser
6
7
/**
8
 * XMLValidate.java
9
 *         Purpose: A Class that validates XML documents
10
 *   			   This class is uses a specific parser
11
 * 				and calls the GenericXMLValidate class
12
 *                 to do the actual validation
13
 *       Copyright: 2000 Regents of the University of California and the
14
 *                  National Center for Ecological Analysis and Synthesis
15
 *                  April 28, 2000
16
 *
17
 * @author Dan Higgins
18
 * @version Version 1.0
19
 */
20
public class XMLValidate
21
{
22
    String doc;
23
    SAXParser par;
24
    public boolean validating = false;
25
26
    public XMLValidate( String docname){
27
        doc = docname;
28
29
            par = new SAXParser();           // works for both Xerces and Oracle
30
/*            try {   //Xerces
31
            par.setFeature("http://xml.org/sax/features/validation",true);
32
            }
33
            catch (Exception e)
34
                {System.out.println("Could not set Validation!!!");
35
                System.exit(0);}
36
                // Xerces end
37
*/
38
39
                par = new SAXParser();           // works for both Xerces and Oracle
40
                par.setValidationMode(true);     // Oracle
41
42
43
44
45
        GenericXMLValidate gxv = new GenericXMLValidate(par);
46
        if (gxv.validate(doc)) {
47
            System.out.println("XML is validated");
48
        }
49
        else {
50
            System.out.print(gxv.returnErrors());
51
        }
52
    }
53
54
55
    public static void main(String[] args) {
56
57
        if (args.length!=1) {
58
            System.out.println("Usage: java XMLValidate <xmlfile or URL>");
59
            System.exit(0);
60
        }
61
        String doc = args[0];
62
63
64
        new XMLValidate(doc);
65
    }
66
67
68
69
}