1

假设我将一个 XML 字符串存储到一个变量中

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

以及与此 XML 相关的架构定义在另一个中:

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

您是否认为有一种方法可以验证和解组“resp”到对象(例如使用 JAXB)?有没有人已经尝试或成功实施了这些东西?

提前,非常感谢您的任何建议... Seb

4

1 回答 1

2

您可以使用Unmarshaller 类的unmarshal(Source source)setSchema(Schema schema)。这应该有效:

unmarshaller.setSchema(SchemaFactory.newSchema(new StreamSource(new StringReader(xsd));
unmarshaller.unmarshal(new StreamSource(new StringReader(resp));
于 2010-01-18T11:25:22.763 回答