2

I am using the JAXB parser to convert XML to a Java object. I have generated the JAXB files from the XML schema (XSD).

While passing the XML String , I defined xsi:noNamespaceSchemaLocation='Typetest.xsd'. So this will validate the XML document against the XML schema Typetest.xsd.

But my question is that I never defined the path for the JAXB parser to grab the schema file.

So how will JAXB determine the path ?

<book xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="TypeTest.xsd">
</book>

1 Answer 1

2

To enable validation on the unmarshal operation you must set an instance of Schema on the Unmarshaller.

Below is a link to an example on my blog:

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for your reply .I have no issues with the validation against the schema.But i am just curious on where actually the unmarshaller finds the path from? from my code , i just pass the xml string to the unmarshaller .Can you help to explain with an example?
@jegadees - The Unmarshaller doesn't find the path. You need to create an instance of Schema and set it on the Unmarshaller yourself. I have added a link to an example in my answer.
exactly the answer i am looking for..Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.