Hi Sagara, I see two issues. The first Mukul already pointed out. "http://www.w3.org/ns/wsdl", "http://www.w3.org/ns/wsdl-extensions" and "http://www.w3.org/2001/XMLSchema" are not schema documents. I suppose these are the target namespaces of the other documents you have in the list. They just happen to resolve to HTML pages on the W3C site. Do not include them here. SchemaFactory only takes schema documents as input.
Your other issue is that you're not actually using Xerces (despite your intentions to do so). The com.sun.org.apache.xerces.* classes are Sun's (aging) fork of the Xerces codebase which they develop/maintain and release in their JDK. It has bugs which are unique to it and others which have long been fixed in Apache. One bug [1] in some versions of the JDK prevents Xerces' SchemaFactory implementation from being loaded normally. You probably got Sun's implementation of SchemaFactory due to this bug. Using the Endorsed Standards Override Mechanism [2][3] (with xml-apis.jar and xercesImpl.jar) will resolve that. Thanks. [1] http://marc.info/?l=xml-commons-dev&m=111898640501739&w=2 [2] http://xerces.apache.org/xerces2-j/faq-general.html#faq-4 [3] http://java.sun.com/j2se/1.5.0/docs/guide/standards/ Michael Glavassevich XML Parser Development IBM Toronto Lab E-mail: [EMAIL PROTECTED] E-mail: [EMAIL PROTECTED] "Sagara Gunathunga" <[EMAIL PROTECTED]> wrote on 11/09/2008 10:34:49 AM: > Hi Guys, > We have a WSDLReader class that uses Xerces-J DOMParser to read > documents in to DOM with validation features set through the org. > apache.xerces.impl.Constants. Now we want to move with JAXP API with > Xerces-J implementation, I'm getting an error when validating with > JAXP but not with the DOMParser. Here I have listed two sample > programs to illustrate this "OldValidation" use DOMParser and work > fine but "NewValidation" use JAXP API and gave following error when > parsing the same documents. > All the documents I used for testing are taken from W3C WSDL 2.0 > Test Suit; please some one can point out where the error is and how > to solve this..? > ( This particular example use document available on [1], you can see > other documents in [2] ) > > [1] http://dev.w3.org/cvsweb/2002/ws/desc/test- > suite/documents/good/FlickrHTTP-1G/ > [2] http://dev.w3.org/cvsweb/2002/ws/desc/test-suite/documents/good > > Thanks, > > Sagara Gunathunga > > Blog - ssagara.blogspot.com > Web - http://sagaras.awardspace.com/ > > > =================== Error trace ========================= > > org.xml.sax.SAXParseException: s4s-elt-character: Non-whitespace > characters are not allowed in schema elements other than 'xs: > appinfo' and 'xs:documentation'. Saw 'WSDL 2.0 Namespace'. > at com.sun.org.apache.xerces.internal.util. > ErrorHandlerWrapper.createSAXParseException(Unknown Source) > at com.sun.org.apache.xerces.internal.util. > ErrorHandlerWrapper.error(Unknown Source) > at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter. > reportError(Unknown Source) > at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter. > reportError(Unknown Source) > at com.sun.org.apache.xerces.internal.impl.xs.opti. > SchemaDOMParser.characters(Unknown Source) > at com.sun.org.apache.xerces.internal.impl. > XMLDocumentFragmentScannerImpl.scanContent(Unknown Source) > at com.sun.org.apache.xerces.internal.impl. > XMLDocumentFragmentScannerImpl$FragmentContentDispatcher. > dispatch(Unknown Source) > at com.sun.org.apache.xerces.internal.impl. > XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source) > at com.sun.org.apache.xerces.internal.impl.xs.opti. > SchemaParsingConfig.parse(Unknown Source) > at com.sun.org.apache.xerces.internal.impl.xs.opti. > SchemaParsingConfig.parse(Unknown Source) > at com.sun.org.apache.xerces.internal.impl.xs.traversers. > XSDHandler.getSchema(Unknown Source) > at com.sun.org.apache.xerces.internal.impl.xs.traversers. > XSDHandler.parseSchema(Unknown Source) > at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaLoader. > loadSchema(Unknown Source) > at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaLoader. > loadGrammar(Unknown Source) > at com.sun.org.apache.xerces.internal.jaxp.validation.xs. > SchemaFactoryImpl.newSchema(Unknown Source) > at samples.NewValidtor.main(NewValidtor.java:42) > > ========================= OldValidation =========================== > public class OldValidation { > > public static void main(String[] args) { > > String inputPath = "D:\\flickr.wsdl"; > DOMParser parser = new DOMParser(); > > try { > // parser.setFeature(org.apache.xerces.impl. > Constants.SAX_FEATURE_PREFIX > // + org.apache.xerces.impl.Constants. > NAMESPACES_FEATURE, true); > // parser.setFeature(org.apache.xerces.impl. > Constants.SAX_FEATURE_PREFIX > // + org.apache.xerces.impl.Constants. > NAMESPACE_PREFIXES_FEATURE, > // true); > parser > .setFeature( > org.apache.xerces.impl.Constants. > SAX_FEATURE_PREFIX > + org.apache. > xerces.impl.Constants.VALIDATION_FEATURE, > true); > parser > .setFeature( > org.apache.xerces.impl.Constants. > XERCES_FEATURE_PREFIX > + org.apache. > xerces.impl.Constants.SCHEMA_VALIDATION_FEATURE, > true); > parser > .setProperty( > org.apache.xerces.impl.Constants. > XERCES_PROPERTY_PREFIX > + org.apache. > xerces.impl.Constants.SCHEMA_LOCATION, > "http://www.w3.org/ns/wsdl " > + " http: > //www.w3.org/2007/03/wsdl/wsdl20.xsd" > + " http: > //www.w3.org/ns/wsdl-extensions " > + " http: > //www.w3.org/2007/03/wsdl/wsdl20-extensions.xsd" > + " http: > //www.w3.org/2001/XMLSchema " > + " http: > //www.w3.org/2001/XMLSchema.xsd"); > Document doc = null; > parser.parse(inputPath); > doc = parser.getDocument(); > System.out.println("Validation is ok"); > } catch (SAXNotRecognizedException e) { > e.printStackTrace(); > > } catch (SAXNotSupportedException e) { > e.printStackTrace(); > } catch (SAXException e) { > e.printStackTrace(); > } catch (IOException e) { > e.printStackTrace(); > } > > } > > } > > > ========================= NewValidation =========================== > public class NewValidation { > > public static void main(String[] args) { > String inputPath = "D:\\flickr.wsdl"; > > Vector<String> schemas = new Vector(); > schemas.add("http://www.w3.org/ns/wsdl "); > schemas.add(" http://www.w3.org/2007/03/wsdl/wsdl20.xsd"); > schemas.add(" http://www.w3.org/ns/wsdl-extensions "); > schemas.add(" http://www.w3.org/2007/03/wsdl/wsdl20-extensions.xsd > "); > schemas.add(" http://www.w3.org/2001/XMLSchema "); > schemas.add(" http://www.w3.org/2001/XMLSchema.xsd"); > try { > Schema schema = null; > Document doc = null; > SchemaFactory factory = SchemaFactory > .newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI > ); > // factory.setErrorHandler(parserAPIUsage); > final int length = schemas.size(); > StreamSource[] sources = new StreamSource[length]; > for (int j = 0; j < length; ++j) { > sources[j] = new StreamSource((String) > schemas.elementAt(j)); > } > schema = factory.newSchema(sources); > > DocumentBuilderFactory dbf = DocumentBuilderFactory. > newInstance(); > dbf.setValidating(true); > dbf.setNamespaceAware(true); > dbf.setSchema(schema); > DocumentBuilder db = dbf.newDocumentBuilder(); > > // db.setErrorHandler(parserAPIUsage); > doc = db.parse(inputPath); > System.out.println("Validation is ok"); > } > > catch (SAXException e) { > e.printStackTrace(); > } catch (ParserConfigurationException e) { > e.printStackTrace(); > } catch (IOException e) { > e.printStackTrace(); > } > > } > > }