• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

XML Schema Validation.

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 com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(Unknown Source)
at com.bwi.oddr.activity.ModifyMessageDeliveryActivity$Worker.run(ModifyMessageDeliveryActivity.java:99)
at java.lang.Thread.run(Unknown 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="http://castor.exolab.org/" Version="4.0" PrimaryLangID="en_US">

Here is the schema (with the middle omitted):

<?xml version = '1.0' encoding = 'UTF-8'?>
<xs:schema targetNamespace="http://www.opentravel.org/OTA/2003/05" elementFormDefault="qualified" version="4.000" id="OTA2005B" xmlns="http://www.opentravel.org/OTA/2003/05" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<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 http://www.opentravel.org/ota_downloads_form.cfm</xs:documentation>;
<xs:element name="OTA_HotelDescriptiveContentNotifRQ">

Java Code:

DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();

SchemaFactory schemaFactory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");

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: 21443
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