Part V. 数据访问-21. 使用O/X Mappers编组XML-21.5 JAXB

前端之家收集整理的这篇文章主要介绍了Part V. 数据访问-21. 使用O/X Mappers编组XML-21.5 JAXB前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

JAXB绑定编译器将W3C XML模式转换为一个或多个Java类,jaxb.properties文件以及可能的一些资源文件。 JAXB还提供了一种从注释Java类生成模式的方法

Spring支持JAXB 2.0 API作为XML编组策略,遵循第21.2节“Marshaller和Unmarshaller”中描述的MarshallerUnmarshaller接口。 相应的集成类驻留在org.springframework.oxm.jaxb@H_502_11@包中。

21.5.1 Jaxb2Marshaller

Jaxb2Marshaller类实现了SpringUnmarshaller接口。 它需要一个上下文路径来操作,您可以使用contextPath属性进行设置。 上下文路径是包含模式派生类的冒号(:)分离的Java包名称的列表。 它还提供了一个classesToBeBound属性,它允许您设置要由编组器支持的类的数组。 通过向bean指定一个或多个模式资源来执行模式验证,如下所示:

<beans@H_502_11@>@H_502_11@
<bean@H_502_11@ id@H_502_11@="jaxb2Marshaller"@H_502_11@ class@H_502_11@="org.springframework.oxm.jaxb.Jaxb2Marshaller"@H_502_11@>@H_502_11@
<property@H_502_11@ name@H_502_11@="classesToBeBound"@H_502_11@>@H_502_11@
<list@H_502_11@>@H_502_11@
<value@H_502_11@>@H_502_11@org.springframework.oxm.jaxb.Flight</value@H_502_11@>@H_502_11@
<value@H_502_11@>@H_502_11@org.springframework.oxm.jaxb.Flights</value@H_502_11@>@H_502_11@
</list@H_502_11@>@H_502_11@
</property@H_502_11@>@H_502_11@
<property@H_502_11@ name@H_502_11@="schema"@H_502_11@ value@H_502_11@="classpath:org/springframework/oxm/schema.xsd"@H_502_11@/>@H_502_11@
</bean@H_502_11@>@H_502_11@

...

</beans@H_502_11@>@H_502_11@

基于XML Schema的配置

jaxb2-marshaller标签配置了一个org.springframework.oxm.jaxb.Jaxb2Marshaller。 这是一个例子:

<oxm:jaxb2-marshaller@H_502_11@ id@H_502_11@="marshaller"@H_502_11@ contextPath@H_502_11@="org.springframework.ws.samples.airline.schema"@H_502_11@/>@H_502_11@

或者,可以通过待绑定的子标签将绑定的类列表提供给编组者:

"marshaller"@H_502_11@>@H_502_11@
<oxm:class-to-be-bound@H_502_11@ name@H_502_11@="org.springframework.ws.samples.airline.schema.Airport"@H_502_11@/>@H_502_11@
<oxm:class-to-be-bound@H_502_11@ name@H_502_11@="org.springframework.ws.samples.airline.schema.Flight"@H_502_11@/>@H_502_11@
...
</oxm:jaxb2-marshaller@H_502_11@>@H_502_11@

可用属性有:

Attribute Description required
id the id of the marshaller no
contextPath the JAXB Context path no

猜你在找的XML相关文章