Hi Julie, Not sure what's wrong here (since you've left out some details), but you may find it easier to get this working using the JAXP 1.3 Validation API. You can compile your schema using the SchemaFactory [1] and then use the Schema [2] object it returns for validation. Schema location hints specified in your instance document will be ignored. There are samples [3][4] included in the binary distribution which show how to do this.
Thanks. [1] http://xerces.apache.org/xerces2-j/javadocs/api/javax/xml/validation/SchemaFactory.html [2] http://xerces.apache.org/xerces2-j/javadocs/api/javax/xml/validation/Schema.html [3] http://xerces.apache.org/xerces2-j/samples-jaxp.html#SourceValidator [4] http://xerces.apache.org/xerces2-j/samples-jaxp.html#ParserAPIUsage Michael Glavassevich XML Parser Development IBM Toronto Lab E-mail: [EMAIL PROTECTED] E-mail: [EMAIL PROTECTED] [EMAIL PROTECTED] wrote on 04/03/2007 09:33:25 PM: > 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 --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]