473,795 Members | 2,974 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Schema validation

I have a problem with the code sample below, basically when i run it i
get the error
classnotfoundex ception org.apache.xerc es.parsers.SAXP arser
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.IOExcep tion;
import org.xml.sax.XML Reader;
import org.apache.xerc es.parsers.SAXP arser;

import org.xml.sax.hel pers.DefaultHan dler;
import org.xml.sax.hel pers.XMLReaderF actory;
import org.xml.sax.SAX Exception;
import org.xml.sax.SAX ParseException;
class XMLReaderValida tor {
public static void main(String args[]) {

String parserClass = "org.apache.xer ces.parsers.SAX Parser";
String validationFeatu re
= "http://xml.org/sax/features/validation";
String schemaFeature
= "http://apache.org/xml/features/validation/schema";
try {
String x = "<xml></xml>"; //args[0];
XMLReader r = XMLReaderFactor y.createXMLRead er(parserClass) ;
r.setFeature(va lidationFeature ,true);
r.setFeature(sc hemaFeature,tru e);
r.setErrorHandl er(new MyErrorHandler( ));
r.parse(x);
} catch (SAXException e) {
System.out.prin tln(e.toString( ));
} catch (IOException e) {
System.out.prin tln(e.toString( ));
}
}
private static class MyErrorHandler extends DefaultHandler {
public void warning(SAXPars eException e) throws SAXException {
System.out.prin tln("Warning: ");
printInfo(e);
}
public void error(SAXParseE xception e) throws SAXException {
System.out.prin tln("Error: ");
printInfo(e);
}
public void fatalError(SAXP arseException e) throws SAXException {
System.out.prin tln("Fattal error: ");
printInfo(e);
}
private void printInfo(SAXPa rseException e) {
System.out.prin tln(" Public ID: "+e.getPublicId ());
System.out.prin tln(" System ID: "+e.getSystemId ());
System.out.prin tln(" Line number: "+e.getLineNumb er());
System.out.prin tln(" Column number: "+e.getColumnNu mber());
System.out.prin tln(" Message: "+e.getMessage( ));
}
}
}
Jul 20 '05 #1
0 1742

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

Similar topics

2
1796
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 been able to do it using a schema, which I need to do. Example: <data> <item><fld1>1</fld2><fld2>2</fld2></item>
9
4440
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 completed a certain point in the system, but that will still be present in the file. At points later in the system, when these files are read in, I do not want to validate this section as it has already been validated much earlier, but still need the...
2
9453
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. Actually, second time I do a deserialization, the data from XML is fed directly to an object. The problem I am experiencing is the error at the second reading attempt, and error description implies that reader is winded to the end of the XML and...
0
1138
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: <mycontrolns:mycontrol id="test" runat="server"> <mytemplate>test</mytemplate> </mycontrolns> and I was able to specify the XSD to validate "mytemplate" as the only valid child type for "mycontrol". Here's a challenge: Is there anyway
1
6410
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 reference this wsdl in .NET it seems to do it fine, yet there are no objects to reference except RateQuoteBeanService. In the WSDL it looks like there should be getRateQuote, and QUOTEREQUEST, etc.
0
2158
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) and the custom error message throw during validation for the end user. I know .NET enable it using errorMessage tag, but with a standard W3C java validation ... If is it possible, does it works in IE too? Like that the same XSD file could be...
5
3685
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 validation? The former seems to be an easier question to answer. XML files will arrive from around the world and must be schema validated before further processing and loading into a database, so I'm trying to foresee the various layouts that might be...
0
1421
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 the add () method. The add () method returned E_FALSE. When I referred the MSDN library, it states that "E_FAIL is returned if: · The collection is read-only · The document is not a recognized schema
2
3684
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" targetNamespace="http://www.temp.com/ContactsImport" xmlns="http://www.temp.com/ContactsImport" elementFormDefault="qualified"> <xs:element name="Contacts"> <xs:complexType> <xs:sequence>
0
1701
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: http://eptstest-integra.sodra.lt/orabpel/epts/surastiAsmenis/surastiAsmenis?wsdl Have tried with Altova XML spy and SoapUI 3.5. Descriptors load well except WseWsdl3.exe tool. Using such proxy class is ok until you get fault response, then everything is translated to "business...
0
9672
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10439
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10165
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10001
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9043
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7541
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5437
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5563
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3727
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.