1

XML 文字列を変数に格納するとします。

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

この XML に関連するスキーマ定義は、別の 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 に答える