具有指定模式的JAXB Marshaller [英] JAXB Marshaller with specified schema

查看:136
本文介绍了具有指定模式的JAXB Marshaller的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我编组的每个xml文件中定义模式。然后在解组过程中获取此模式(路径字符串)。 marshaller.setSchema()

I want define schema in each xml file that I marshalling. And then get this schema (path string) at unmarshalling process. marshaller.setSchema() only


允许调用者将编组的XML验证为它是编组的。

allows the caller to validate the marshalled XML as it's marshalled.

是的,我可以为此目的编写额外的bean,但我希望得到xml像

Yes, I can write extra bean for this purpose, but I want get xml like

<root
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:noNamespaceSchemaLocation='bla-bla.xsd'>...


推荐答案

要指定noNamespaceSchemaLocation,您可以执行以下操作:

To specify a noNamespaceSchemaLocation you can do the following:

JAXBContext jc = JAXBContext.newInstance(Root.class);
Marshaller marshaller = jc.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_NO_NAMESPACE_SCHEMA_LOCATION, "bla-bla.xsd");

这篇关于具有指定模式的JAXB Marshaller的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆