| Author |
XML Schema Validation.
|
Benjamin Hundley
Ranch Hand
Joined: Mar 06, 2006
Posts: 53
|
|
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"?>
<OTA_HotelDescriptiveContentNotifRQ
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:cust="xalan://com.bwi.oddr.xmloperations.CustomFunctions"
xmlns:ns1="http://castor.exolab.org/" Version="4.0" PrimaryLangID="en_US">
...
</OTA_HotelDescriptiveContentNotifRQ>
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:annotation>
<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:annotation>
<xs:element name="OTA_HotelDescriptiveContentNotifRQ">
...
</xs:element>
Java Code:
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setValidating(false);
factory.setNamespaceAware(true);
SchemaFactory schemaFactory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
File schemaFile = new File(
"FS_OTA_HotelDescriptiveContentNotifRQ.xsd");
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
Bartender
Joined: Oct 14, 2005
Posts: 16483
|
|
|
"Content is not allowed in prolog"... that's nothing to do with Schemas. Commonly it just means there's whitespace before the root element.
|
 |
 |
|
|
subject: XML Schema Validation.
|
|
|