In-memory unmarshalling, from an XML string and its schema stored in a string too, possible?
Let's suppose I store an XML string into a variable
String resp = new String("<?xml version=\"1.0\" encodin..."开发者_如何学Python);
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
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));
精彩评论