Hi.

I am receiving XML documents from a number of different companies.
The documents I receive can contain a variety of different schema/dtd 
declarations
eg 
<!DOCTYPE OrderResponse SYSTEM "XCBL30.dtd">
<?soxtype 
urn:x-commerceone:document:com:commerceone:XCBL30:XCBL30.sox$1.0?>
<Order xmlns="rrn:org.xcbl:schemas/xcbl/v3_0/xcbl30.xsd" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xsi:schemaLocation="rrn:org.xcbl:schemas/xcbl/v3_0/xcbl30.xsd Order.xsd">
or even no declaration at all.

I want to validate the documents that I receive against a xsd schema, 
disregarding the declaration contained in the document.

I thought that I would be able to achieve this by writing my own 
EntityResolver, and always resolve to a shema, however I have found that 
this doesn't work.
It only works when a xsd schema declaration is passed.

For both sox schema declarations and no declaration I get : 
ERROR-cvc-elt.1: Cannot find the declaration of element 'OrderResponse'. 
before the resolveEntity method of the Entity Resolver is even called.

For dtd declaration I get : SAXException - The markup declarations 
contained or pointed to by the document type declaration must be 
well-formed. after the EntityResolver is called.

I am using the org.apache.xerces.parsers.SAXParser to perform the 
validation.

         SAXParser parser = new SAXParser(); 
 
parser.setProperty("http://apache.org/xml/properties/internal/grammar-pool";, 
grammarCache); 
         parser.setFeature("http://xml.org/sax/features/validation";, 
true); 
 parser.setFeature("http://apache.org/xml/features/validation/schema";, 
true);
 
         SchemaEntityResolver etyRes = new SchemaEntityResolver();
         etyRes.setSchemaLocation(the_location);
         etyRes.setFormat("XCBL");
         etyRes.setVersion("30");
         etyRes.setSchemaName(schemaName);  // just sets the name of the 
schema to use

         ValidationHandler handler = new ValidationHandler();
         parser.setErrorHandler(handler);

         parser.setEntityResolver(etyRes);

         StringReader stringReader = new StringReader(the_document);
         InputSource inSource = new InputSource(stringReader);
         parser.parse(inSource);

Does anyone know of any way I can force my document to be validated 
against a schema.
Or do I have to manipulate the received document to remove the passed 
declarations, and insert my own.

Thanks

-- 
This transmission is for the intended addressee only and is confidential 
information. If you have received this transmission in error, please notify the 
sender and delete the transmission. The contents of this e-mail are the opinion 
of the writer only and are not endorsed by the Mincom Group of companies unless 
expressly stated otherwise.
-- 





Reply via email to