从 XML 字符串及其存储在字符串中的模式进行内存中解组,可能吗?

发布于 2024-08-18 04:59:53 字数 351 浏览 7 评论 0原文

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

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

,并将与此 XML 相关的模式定义存储在另一个变量中:

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

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

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

闻呓 2024-08-25 04:59:53

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

unmarshaller.setSchema(SchemaFactory.newSchema(new StreamSource(new StringReader(xsd));
unmarshaller.unmarshal(new StreamSource(new StringReader(resp));

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));
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文