1
我正在使用Jaxb2Marshaller並使用ValidationEventHandler-handleEvent()。我在映射過程中存儲發生的任何錯誤消息。我使用xsd來驗證強制/可選標記。所以這個問題取決於xml中一個標籤的值,其他一些標籤的值可能成爲強制/可選的。如何通過xsd在java中驗證xml取決於xml元素的值
現在對於所有的情況,我已經做了單獨的xsd,嘗試檢查各自的必填字段。但我怎麼能告訴jaxb,以驗證應該使用xsd的xml?
<bean id="jaxb2MarshallerForABC" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
<property name="contextPath">
<util:constant
static-field="com.abc.pqr.util.ABCMessageConstants.PACKAGE_DATAMODEL_AB_IN_OB" />
</property>
<property name="schemas">
<value>
classpath:xsd/tc/oa/in/InboundMessageIss.xsd <!--Depending on xml value validate with different xsd/since there could be diffent tag as mandatory/optional -->
</value>
</property>
<property name="unmarshallerListener" ref="unMarshallingListenerForOA"/>
<property name="validationEventHandler" ref="validationEventHandler" />
</bean>