Posted By:
swarnim_ranjitkar
Posted On:
Friday, April 11, 2003 06:56 PM
does any one came across this **************************************************** package saxpars; import java.io.IOException; import org.xml.sax.*; import org.xml.sax.helpers.*; import org.apache.xerces.parsers.DOMParser; public class SaxParser1 extends DefaultHandler { public static void main(String[] argv) { if (argv.length != 1) { System.out.println("Usage: java SaxParser1 [URI]"); System.exit(0); } String uri = argv[0]; try { DOMParser UEXParser = new DOMParser(); UEXParser.setFeature("http://xml.org/sax/features/namespaces", true); UEXParser.setFeature("http://xml.org/sax/features/validatio
More>>
does any one came across this
****************************************************
package saxpars;
import java.io.IOException;
import org.xml.sax.*;
import org.xml.sax.helpers.*;
import org.apache.xerces.parsers.DOMParser;
public class SaxParser1 extends DefaultHandler {
public static void main(String[] argv) {
if (argv.length != 1) {
System.out.println("Usage: java SaxParser1 [URI]");
System.exit(0);
}
String uri = argv[0];
try {
DOMParser UEXParser = new DOMParser();
UEXParser.setFeature("http://xml.org/sax/features/namespaces", true);
UEXParser.setFeature("http://xml.org/sax/features/validation", true);
UEXParser.setFeature("http://apache.org/xml/features/validation/schema", true);
UEXParser.setFeature("http://apache.org/xml/features/validation/schema-full-checking", false);
UEXParser.setProperty("http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation","c:/Edi/modi850.xsd");
UEXParser.setErrorHandler(new MyErrorHandler());
UEXParser.parse(uri);
}
catch(IOException ioe) {
ioe.printStackTrace();
}
catch(SAXParseException e){
if(/*!e.getMessage().startsWith("cvc-attribute.3: The value '' of attribute 'Val'")*/
!e.getMessage().startsWith("cvc-complex-type.4: Attribute 'Val' must appear on element ")
&& (!e.getMessage().startsWith("cvc-complex-type.2.3: Element ")
&& !e.getMessage().endsWith(" must have no character [children], because the types content type is element-only."))
&& !e.getMessage().startsWith("cvc-complex-type.2.4.b: The content of element ")
&& !e.getMessage().startsWith("a-props-correct.2: Invalid value constraint value ''")){
//Settings.setValue("validate.error","true");
System.out.println("313: Parser Error1: "+e.getMessage());
}
}
catch(SAXException saxe) {
saxe.printStackTrace();
}
catch(Exception e){e.getMessage();}
}
}
class MyErrorHandler implements ErrorHandler {
private void print (String label, SAXParseException e){
System.out.println("313: " + label + ": " + e.getMessage () +" at " +e.getLineNumber ());
}
boolean reportErrors = true;
boolean abortOnErrors = false;
// for recoverable errors, like validity problems
public void error (SAXParseException e)throws SAXException{
if (reportErrors){
if(/*!e.getMessage().startsWith("cvc-attribute.3: The value '' of attribute 'Val'")*/
!e.getMessage().startsWith("cvc-complex-type.4: Attribute 'Val' must appear on element ")
&& (!e.getMessage().startsWith("cvc-complex-type.2.3: Element ")
&& !e.getMessage().endsWith(" must have no character [children], because the types content type is element-only."))
&& !e.getMessage().startsWith("cvc-complex-type.2.4.b: The content of element ")
&& !e.getMessage().startsWith("a-props-correct.2: Invalid value constraint value ''")){
//Settings.setValue("validate.error","true");
System.out.println("313: Parser Error: "+e.getMessage());
}
}
if (abortOnErrors)
throw e;
}
public void fatalError (SAXParseException e)throws SAXException {
if (reportErrors){
//Settings.setValue("validate.error","true");
System.out.println("313: Parser Error : "+e.getMessage());
}
//print ("error", e);
if (abortOnErrors)
throw e;
}
public void warning (SAXParseException e)throws SAXException{
if (reportErrors){
System.out.println("314: Parser Warning : "+e.getMessage());
}
//print ("error", e);
if (abortOnErrors)
throw e;
}
}
--xml file
<?xml version="1.0" encoding="UTF-8"?>
---------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>