472,961 Members | 2,145 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Java XML Validation Problem

I am having alot of trouble getting a XML document validated with a

I got a sample document and schema off of w3schools.com, which passed
an online xml validator:
http://tools.decisionsoft.com/schemaValidate.html. I cannot, however,
get them validated programmatically.

The documents are:


<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified"><xs:element name="note">
<xs:element name="to" type="xs:string"/>
<xs:element name="from" type="xs:string"/>
<xs:element name="heading" type="xs:string"/>
<xs:element name="body" type="xs:string"/>


<?xml version="1.0"?>
xsi:schemaLocation="http://www.w3schools.com note.xsd">

<body>Don't forget me this weekend!</body>

I'm using java 1.5 currently, although I had problems with 1.4 and
xerces, so I'm pretty confident the problem isn't related to the java

My code is:

DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
SchemaFactory sFact =
SchemaFactory.newInstance(XMLConstants.W3C_XML_SCH EMA_NS_URI);

factory.setSchema(sFact.newSchema(new java.io.File(SCHEMA_FILE)));

DocumentBuilder builder = factory.newDocumentBuilder();
builder.setErrorHandler(new ErrorHandler() {
public void warning (SAXParseException exception) throws SAXException
public void error (SAXParseException exception) throws SAXException {
public void fatalError (SAXParseException exception) throws
SAXException {

org.w3c.dom.Document doc = builder.parse(file);
The error I recieve is:

Exception in thread "main" java.lang.IllegalStateException
at com.sun.org.apache.xerces.internal.jaxp.validation .ValidatorHandlerImpl$3.checkState(ValidatorHandle rImpl.java:411)
at com.sun.org.apache.xerces.internal.jaxp.validation .ValidatorHandlerImpl$3.getElementTypeInfo(Validat orHandlerImpl.java:441)
at com.sun.org.apache.xerces.internal.jaxp.JAXPValida torComponent$SAX2XNI.elementAug(JAXPValidatorCompo nent.java:299)
at com.sun.org.apache.xerces.internal.jaxp.JAXPValida torComponent$SAX2XNI.endElement(JAXPValidatorCompo nent.java:291)
at com.sun.org.apache.xerces.internal.jaxp.XNI2SAX.en dElement(XNI2SAX.java:163)
at com.sun.org.apache.xerces.internal.jaxp.validation .XNI2SAXEx.endElement(XNI2SAXEx.java:108)
at com.sun.org.apache.xerces.internal.impl.xs.XMLSche maValidator.endElement(XMLSchemaValidator.java:818 )
at com.sun.org.apache.xerces.internal.jaxp.validation .ValidatorHandlerImpl.endElement(ValidatorHandlerI mpl.java:339)
at com.sun.org.apache.xerces.internal.jaxp.XNI2SAX.en dElement(XNI2SAX.java:163)
at com.sun.org.apache.xerces.internal.jaxp.JAXPValida torComponent.endElement(JAXPValidatorComponent.jav a:206)
at com.sun.org.apache.xerces.internal.xinclude.XInclu deHandler.endElement(XIncludeHandler.java:790)
at com.sun.org.apache.xerces.internal.impl.XMLDocumen tFragmentScannerImpl.scanEndElement(XMLDocumentFra gmentScannerImpl.java:1241)
at com.sun.org.apache.xerces.internal.impl.XMLDocumen tFragmentScannerImpl$FragmentContentDispatcher.dis patch(XMLDocumentFragmentScannerImpl.java:1685)
at com.sun.org.apache.xerces.internal.impl.XMLDocumen tFragmentScannerImpl.scanDocument(XMLDocumentFragm entScannerImpl.java:368)
at com.sun.org.apache.xerces.internal.parsers.XML11Co nfiguration.parse(XML11Configuration.java:834)
at com.sun.org.apache.xerces.internal.parsers.XML11Co nfiguration.parse(XML11Configuration.java:764)
at com.sun.org.apache.xerces.internal.parsers.XMLPars er.parse(XMLParser.java:148)
at com.sun.org.apache.xerces.internal.parsers.DOMPars er.parse(DOMParser.java:248)
at com.sun.org.apache.xerces.internal.jaxp.DocumentBu ilderImpl.parse(DocumentBuilderImpl.java:292)
at javax.xml.parsers.DocumentBuilder.parse(DocumentBu ilder.java:169)

I am behind a web proxy, and I don't know if the validation process
involves retrieving files at the URLs in the xml and xsd files, which
could be the problem.

can someone shed some light on this?

Thanks in advance.
Jul 20 '05 #1
0 4064

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

Similar topics

by: Dave W | last post by:
I wish to validate a string but i'm not quite sure how to go about doing it. I'd like to ensure that it is 9 characters long and in the following format. "LL 00 LLL" - Thats letter, letter,...
by: Ulf Nordlund | last post by:
I am using an XML schema to check (validate) the structure of an XML document. But since I cannot check everything I need using a schema, I am thinking of using XSL for more detailed checks (value...
by: Marcin Cenkier | last post by:
Hi, I can create a schema from xsd file: Schema s = SchemaFactory.newInstance(_XMLConstants.W3C_XML_SCHEMA_NS_URI_).newSchema(new StreamSource(res.getInputStream())); but when using...
by: Jobs | last post by:
Download the JAVA , .NET and SQL Server interview with answers Download the JAVA , .NET and SQL Server interview sheet and rate yourself. This will help you judge yourself are you really worth of...
by: Francois Stander | last post by:
Hi, hope someone can help me. It seems imposible to read data from a server, however, I can read the validation data from the server and hold it in dataviews . datasets or data tables in my asp...
by: ahsan19 | last post by:
Our company is doing a project for the City of Chicago and we are trying to communicate with their servers using web services. Their environment is java based but we are using .NET on our end. The...
by: jaimemartin | last post by:
hello, I want to validate an xml by means of a schema (xsd). To do that first of all Im using a SchemaFactory. The problem is that if I run the code in Windows all works fine, but If I run it in...
by: poornimanithya76 | last post by:
Hi, I am having grid view an my page which is having template fields(text box, check box and drop down).If user clicks on check box i need to consider text box and drop down as a required fields.i...
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.