开发者

JAXB Marshaller with specified schema

开发者 https://www.devze.com 2023-01-31 16:44 出处:网络
I want define schema in each xml file that I marshalling. And then get this schema (path string) at unmarshalling process. marshaller.setSchema() only

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

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

开发者_Python百科

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'>...


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

精彩评论

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