Reputation: 1262
I need to validate my web service objects against an xsd and i'm doing it by :
SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
factory.setResourceResolver(new ResourceResolver());
Source schemaFile = new StreamSource('Input stream with my xsd');
factory.newSchema(schemaFile);
the last line - factory.newSchema(schemaFile); throws and exception when using an xsd file that uses soap-enc namespace. Below are parts of the xsd file, the namespace declaration and the complex type that uses the namespace.
<xsd:schema
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap-enc="http://schemas.xmlsoap.org/soap/encoding/">
<xsd:complexType name="name">
<xsd:sequence>
<xsd:element name="id" type="xsd:string"/>
<xsd:element name="names" type="soap-enc:Array"/>
</xsd:sequence>
</xsd:complexType>
The exception is: org.xml.sax.SAXParseException; lineNumber: 20; columnNumber: 62; src-resolve.4.2: Error resolving component 'soap-enc:Array'. It was detected that 'soap-enc:Array' is in namespace 'http://schemas.xmlsoap.org/soap/encoding/', but components from this namespace are not referenceable from schema document 'null'. If this is the incorrect namespace, perhaps the prefix of 'soap-enc:Array' needs to be changed. If this is the correct namespace, then an appropriate 'import' tag should be added to 'null'.
Upvotes: 0
Views: 2045
Reputation: 31300
This XML schema refers to type soap-enc:Array which isn't defined in this schema file. So you must include the file defining it:
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap-enc="http://schemas.xmlsoap.org/soap/encoding/">
<xsd:import namespace="http://schemas.xmlsoap.org/soap/encoding/"
schemaLocation="..."/>
<!-- ...
You find the appropriate XML schema on the web at the location defining the namespace. I think it's best to download it and use it from your local filesystem, which is usually more efficient if you need it frequently. Using the URL as schemaLocation should work too, though.
Upvotes: 1