Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

XML Schema Validation.  RSS feed

Benjamin Hundley
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 22480
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Content is not allowed in prolog"... that's nothing to do with Schemas. Commonly it just means there's whitespace before the root element.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!