Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

validation error for valid xml [SWS-35] #188

Closed
gregturn opened this issue Jun 21, 2006 · 1 comment
Closed

validation error for valid xml [SWS-35] #188

gregturn opened this issue Jun 21, 2006 · 1 comment

Comments

@gregturn
Copy link
Contributor

Ingo opened SWS-35 and commented

I've created a web service and i get a validation error in the log file.

DEBUG webservice.CreateDataTypesRequestEndpoint - Marshalling [javax.xml.bind.JAXBElement@1873ad9] to response payload
ERROR endpoint.PayloadValidatingInterceptor - XML validation error on response: UndeclaredPrefix: Cannot resolve 'ns2:AddressDataType' as a QName: the prefix 'ns2' is not declared.
ERROR endpoint.PayloadValidatingInterceptor - XML validation error on response: cvc-elt.4.1: The value 'ns2:AddressDataType' of attribute 'http://www.w3.org/2001/XMLSchema-instance,type' of element 'ns2:casDataType' is not a valid QName.
ERROR endpoint.PayloadValidatingInterceptor - XML validation error on response: UndeclaredPrefix: Cannot resolve 'ns2:AddressDataType' as a QName: the prefix 'ns2' is not declared.
ERROR endpoint.PayloadValidatingInterceptor - XML validation error on response: cvc-attribute.3: The value 'ns2:AddressDataType' of attribute 'xsi:type' on element 'ns2:casDataType' is not valid with respect to its type, 'QName'.
ERROR endpoint.PayloadValidatingInterceptor - XML validation error on response: cvc-complex-type.2.4.d: Invalid content was found starting with element 'ns2:firstName'. No child element is expected at this point.

The following code is my SOAP response:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header />
SOAP-ENV:Body
<ns2:createDataTypesResponse xmlns:ns2="http://springws.cas.de">
<ns2:casDataType
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:type="ns2:AddressDataType">
ns2:key123</ns2:key>
ns2:firstNameFritz</ns2:firstName>
ns2:lastNameMeier</ns2:lastName>
</ns2:casDataType>
</ns2:createDataTypesResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

My XSD looks like this:

<?xml version="1.0" encoding="UTF-8"?>

<schema
xmlns="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" attributeFormDefault="qualified"
targetNamespace="http://springws.cas.de"
xmlns:tns="http://springws.cas.de" >

<complexType name="CasDataType" >
	<sequence>
		<element name="key"		type="long"		nillable="false" minOccurs="1" maxOccurs="1"/>
	</sequence>
</complexType>

<complexType name="AddressDataType">
	<complexContent>
		<extension base="tns:CasDataType">
			<sequence>
				<element name="firstName"	nillable="true" minOccurs="0" type="string"/>
				<element name="lastName"	nillable="true" minOccurs="0" type="string"/>
			</sequence>
		</extension>
	</complexContent>
</complexType>

<complexType name="ArrayOfCasDataTypes">
	<sequence>
		<element name="casDataType" 		type="tns:CasDataType"	nillable="false" minOccurs="1" maxOccurs="unbounded"/>
	</sequence>
</complexType>

<element name="createDataTypesRequest"  type="tns:ArrayOfCasDataTypes"/>

<element name="createDataTypesResponse" type="tns:ArrayOfCasDataTypes"/>

</schema>
This code says that my xml is valid:
SchemaFactory factory = SchemaFactory.newInstance(XMLConstants. W3C_XML_SCHEMA_NS_URI);
Schema schema = factory.newSchema(new File("schema.xsd"));
Validator validator = schema.newValidator();
validator.validate(new StreamSource(new File("payload.xml")));


Affects: 1.0 M1

@gregturn
Copy link
Contributor Author

Arjen Poutsma commented

After some debugging, I've found out that this is a bug of the JAXP api's built in to the JDK.

You can fix it by making sure that you use the Xerces version of the SchemaFactory, and not the JDK internal one. The algorithm for choosing a SchemaFactory is explained at http://java.sun.com/j2se/1.5.0/docs/api/javax/xml/validation/SchemaFactory.html#newInstance(java.lang.String). It comes down to setting the System property "javax.xml.validation.SchemaFactory:http://www.w3.org/2001/XMLSchema" to the value "org.apache.xerces.jaxp.validation.XMLSchemaFactory".

Note that just adding Xerces to your classpath won't fix this, for reasons explained at http://xerces.apache.org/xerces2-j/faq-general.html#faq-4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants