0

I am facing the below error when JABX unmarshaller tries to unmarshall the xml

Exception in thread "main" javax.xml.bind.UnmarshalException - with linked exception: [org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 456; The prefix "xsi" for attribute "xsi:nil" associated with an element type "customerProductStatus" is not bound.]

When I looked at the xml being returned from the server , it is the below :

<customerProductStatus xsi:nil = "true"></customerProductStatus>

I don't see xsi defined in any of the parent tags. Is it possible to add the schemaLocation to unmarshaller without changing any of the bindings?

JAXBContext jaxbContext1 = JAXBContext.newInstance(Request.class);
Unmarshaller jaxbUnMarshaller1 = jaxbContext1.createUnmarshaller();
Request request = (Request)jaxbUnMarshaller1.unmarshal(receiveData.getBinaryStream());
Punter Vicky
  • 15,954
  • 56
  • 188
  • 315

1 Answers1

2

You can add this:

//Gets schema
SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema schema = schemaFactory.newSchema(xmlSchema);

JAXBContext jaxbContext1= JAXBContext.newInstance(Request.class);
Unmarshaller jaxbUnMarshaller1 = jaxbContext1.createUnmarshaller();

//Sets schema with unmarshaller
jaxbUnMarshaller1 .setSchema(schema);

Request request = (Request)jaxbUnMarshaller1.unmarshal(receiveData.getBinaryStream());

The required packages are:

import javax.xml.validation.Schema;
import javax.xml.validation.SchemaFactory;
Jaime Mendes
  • 643
  • 3
  • 9
  • Thanks Jai. I have generated JAXB classes from my WSDL and I don't have a schema file as such. How should I set the schema here : setSchema(schema) – Punter Vicky Sep 01 '13 at 16:48
  • I'm not used to WSDL, can how about this [sample](http://stackoverflow.com/questions/8979044/validating-soap-message-against-wsdl-with-multiple-xsds)? It will use the WSDL file as base to get the schemas. – Jaime Mendes Sep 01 '13 at 17:03
  • Is there a way to update anything in binding.xml to alleviate this issue ? – Punter Vicky Sep 01 '13 at 23:11