Hi Julie, If the target namespace of your schema document is " rrn:org.xcbl:schemas/xcbl/v3_0/xcbl30.xsd" then the documents you have are missing a namespace declaration for that namespace and thus aren't valid against the schema in their current state.
Thanks. Michael Glavassevich XML Parser Development IBM Toronto Lab E-mail: [EMAIL PROTECTED] E-mail: [EMAIL PROTECTED] [EMAIL PROTECTED] wrote on 10/23/2007 01:45:04 AM: > Hi Michael > > Thanks for your response. > I was pulled to another urgent project, so unfortunately had to > leave this unfinished. > However I am back now, and am keen to have another crack at getting > this working. > > As stated previously my requirement is as follows : > > 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 am having some problems implementing the jaxp solution you suggested. > > I have downloaded the latest xerces-2_9_0, and jaxp 1.3. > I am using the sample SourceValidator class, to do as you suggested. > > > However I am finding that the validator does not seem to be using > the schema alone to validate all my documents. > > eg. > I have tried validating the following documents : > > <?xml version="1.0" encoding="UTF-8"?><!DOCTYPE OrderResponse SYSTEM > "XCBL30.dtd"><Order> > <OrderHeader><OrderNumber><BuyerOrderNumber>00000004</BuyerOrderNumber></OrderNumber><OrderIssueDate>20070323T09: > 55:10+10:00</OrderIssueDate><OrderReferences><AccountCode> ...snipped > > error: Parse error occurred - D: > \Eclipse\Workspaces\xerces-2_9_0\xerces-2_9_0\test\XCBL30.dtd (The > system cannot find the file specified) > > > <?xml version="1.0" encoding="UTF-8"?><Order> > <OrderHeader><OrderNumber><BuyerOrderNumber>00000004</BuyerOrderNumber></OrderNumber><OrderIssueDate>20070323T09: > 55:10+10:00</OrderIssueDate> > <OrderReferences><AccountCode>...............snipped > > [Error] NONE_301889302696_Order.txt:2:8: cvc-elt.1: Cannot find the > declaration of element 'Order'. > > <?xml version="1.0"?><?soxtype urn:x-commerceone:document:com: > commerceone:XCBL30:XCBL30.sox$1.0?><Order> > <OrderHeader><OrderNumber><BuyerOrderNumber>00000004</BuyerOrderNumber></OrderNumber><OrderIssueDate>20070323T09: > 55:10+10:00</OrderIssueDate><OrderReferences><AccountCode> > > [Error] SOX_301889302696_Order.txt:2:8: cvc-elt.1: Cannot find the > declaration of element 'Order'. > > <?xml version="1.0" encoding="UTF-8"?> > <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"> > <OrderHeader><OrderNumber><BuyerOrderNumber>00000004</BuyerOrderNumber></OrderNumber><OrderIssueDate>20070323T09: > 55:10+10:00</OrderIssueDate><OrderReferences><AccountCode> > This document is the only one that actually performs the validation. > I am not sure if I am barking up the wrong tree with what I am > trying to do, or whether I just need to manipulate some features or > properties of the validator > ANy feedback you could give would be greatly appreciated. > Thanks > Julie > > > > Michael Glavassevich <[EMAIL PROTECTED]> > 05/04/2007 02:24 PM > > Please respond to > j-users@xerces.apache.org > > To > > j-users@xerces.apache.org > > cc > > [EMAIL PROTECTED] > > Subject > > Re: Validating XML documents against schemas > > > > > 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] --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]