views:

258

answers:

1

Hello, Let's suppose I store an XML string into a variable

String resp = new String("<?xml version=\"1.0\" encodin...");

and the schema definition related to this XML in another one:

String xsd = new String("<xs:schema xmlns="http://schema-...");

do you think there is a way to validate and unmarshall 'resp' into objects (using JAXB for example) ?? Has anybody already tried or successfully implemented such stuff ??

In advance, thanks a lot for any suggestion... Seb

+1  A: 

You can use unmarshal(Source source) and setSchema(Schema schema) of the Unmarshaller class. This should work:

unmarshaller.setSchema(SchemaFactory.newSchema(new StreamSource(new StringReader(xsd));
unmarshaller.unmarshal(new StreamSource(new StringReader(resp));
Thomas Jung
Waow, very interesting indeed. I was looking at the wrong version of Unmarshaller this morning:http://java.sun.com/webservices/docs/1.6/api/javax/xml/bind/Unmarshaller.htmlwhich has no setSchema() method...
Sebastien Rigaud