开发者

In-memory unmarshalling, from an XML string and its schema stored in a string too, possible?

开发者 https://www.devze.com 2022-12-17 04:53 出处:网络
Let\'s suppose I store an XML string into a variable String resp = new String(\"<?xml version=\\\"1.0\\\" encodin...\"开发者_如何学Python);

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));
0

精彩评论

暂无评论...
验证码 换一张
取 消