File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "XML Schema Validation." Watch "XML Schema Validation." New topic
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: 18113
    
    8

"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: http://aspose.com/file-tools
 
subject: XML Schema Validation.
 
Similar Threads
SAXParseException coming while parsing the xml file
WSSecurity, MTOM and TIBCO 5.6
How to get element names from schema
valiating xml using multiple schemas
Axis 1.4 throwing org.xml.sax.SAXException: Invalid element