473,387 Members | 1,492 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Schema validation

I have a problem with the code sample below, basically when i run it i
get the error
classnotfoundexception org.apache.xerces.parsers.SAXParser
now i know the simple answer is declare xerces.jar in your classpath
but i have done that. I have even gotten xerces 2.5...... and still
nothing, i am really struggling here.
see the code below.

import java.io.IOException;
import org.xml.sax.XMLReader;
import org.apache.xerces.parsers.SAXParser;

import org.xml.sax.helpers.DefaultHandler;
import org.xml.sax.helpers.XMLReaderFactory;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
class XMLReaderValidator {
public static void main(String args[]) {

String parserClass = "org.apache.xerces.parsers.SAXParser";
String validationFeature
= "http://xml.org/sax/features/validation";
String schemaFeature
= "http://apache.org/xml/features/validation/schema";
try {
String x = "<xml></xml>"; //args[0];
XMLReader r = XMLReaderFactory.createXMLReader(parserClass);
r.setFeature(validationFeature,true);
r.setFeature(schemaFeature,true);
r.setErrorHandler(new MyErrorHandler());
r.parse(x);
} catch (SAXException e) {
System.out.println(e.toString());
} catch (IOException e) {
System.out.println(e.toString());
}
}
private static class MyErrorHandler extends DefaultHandler {
public void warning(SAXParseException e) throws SAXException {
System.out.println("Warning: ");
printInfo(e);
}
public void error(SAXParseException e) throws SAXException {
System.out.println("Error: ");
printInfo(e);
}
public void fatalError(SAXParseException e) throws SAXException {
System.out.println("Fattal error: ");
printInfo(e);
}
private void printInfo(SAXParseException e) {
System.out.println(" Public ID: "+e.getPublicId());
System.out.println(" System ID: "+e.getSystemId());
System.out.println(" Line number: "+e.getLineNumber());
System.out.println(" Column number: "+e.getColumnNumber());
System.out.println(" Message: "+e.getMessage());
}
}
}
Jul 20 '05 #1
0 1710

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Steve | last post by:
Hi, I have xml data containing "line item" elements and a "footer" element which contains control totals for the line items. While I can easily validate the control totals in xslt, I have not...
9
by: brandon | last post by:
I want to speed up the validation of some of my fairly large and detailed XML files. In particular there is a set of child elements and attributes that does not to be validated after it has...
2
by: Shone | last post by:
I would like to perform a 2-pass XML reading from a stream. Once using the Validating reader, just to confirm the validity against the schema, and next time to do a reading to extract the data....
0
by: Ricky Li | last post by:
I went through some article to see how I can add schema validation for my templated control by adding an XSD file into the VS.NET schema folder. Everything works fine for a schema like this: ...
1
by: billa1972 | last post by:
Hi, I am trying to hook into Yellow Freight's rating webservice. Below is the wsdl. When i try and create a proxy file with wsdl.exe i get the following errors, see below. Also, when i...
0
by: info | last post by:
Hi, Is it possible to include in the Schema validation file, every custom error message for each validation rules? This mean, in the same xsd file we can have the validation rules (patterns)...
5
by: wolf_y | last post by:
My question is simply: under what conditions will empty tags of the form <MOM></MOM> pass schema validation? Of course, the mirror question is: under what conditions will empty tags fail...
0
by: merryla | last post by:
Hi, I tried to perform schema validation. The code works well. But when I tried with the Sample txlife.xsd file from http://acord.org/ I got error in associating the namespace with the xsd i.e. in...
2
by: pnmcosta | last post by:
Hi, I'm fairly new to XML Schema validation. We have XML being imported that must validate against the following schema: <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" ...
0
by: kenkejas | last post by:
Hello public, Got a problem. While generating proxy classes getting warnings: Schema Validation Errors: Error compiling schema. WSDL descriptor is public:...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.