File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes XML and Related Technologies and the fly likes XML Schema Validation. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "XML Schema Validation." Watch "XML Schema Validation." New topic

XML Schema Validation.

Benjamin Hundley
Ranch Hand

Joined: Mar 06, 2006
Posts: 54
I am trying to validate an xml file I have created from an xslt transformation and I am getting an exception.

cvc-elt.1: Cannot find the declaration of element 'OTA_HotelDescriptiveContentNotifRQ'.
[Fatal Error] :1:1: Content is not allowed in prolog.
org.xml.sax.SAXParseException: Content is not allowed in prolog.
at Source)
at Source)
at com.bwi.oddr.activity.ModifyMessageDeliveryActivity$
at Source)

I'm kinda stuck. Can someone help?

Here is the XML file (with the middle omitted):

<?xml version="1.0" encoding="UTF-8"?>
xmlns:ns1="" Version="4.0" PrimaryLangID="en_US">

Here is the schema (with the middle omitted):

<?xml version = '1.0' encoding = 'UTF-8'?>
<xs:schema targetNamespace="" elementFormDefault="qualified" version="4.000" id="OTA2005B" xmlns="" xmlns:xs="">
<xs:documentation xml:lang="en">All Schema files in the OTA specification are made available according to the terms defined by the OTA License Agreement at</xs:documentation>;
<xs:element name="OTA_HotelDescriptiveContentNotifRQ">

Java Code:

DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();

SchemaFactory schemaFactory = SchemaFactory.newInstance("");

File schemaFile = new File(

StreamSource ss = new StreamSource(schemaFile);
factory.setSchema(schemaFactory.newSchema(new Source[] { ss }));

DocumentBuilder builder = factory.newDocumentBuilder();

builder.setErrorHandler(new SimpleErrorHandler());

Document document = builder.parse(new InputSource(new FileReader("test.xml")));
Paul Clapham

Joined: Oct 14, 2005
Posts: 19869

"Content is not allowed in prolog"... that's nothing to do with Schemas. Commonly it just means there's whitespace before the root element.
I agree. Here's the link:
subject: XML Schema Validation.
It's not a secret anymore!