[英]how to validate xml via xsd in java depending on value of an xml element
我正在使用Jaxb2Marshaller並使用ValidationEventHandler-handleEvent()。 我正在將過程中發生的任何錯誤消息存儲在地圖中。 我正在使用xsd驗證強制/可選標簽。 因此,問題取決於xml中標簽的值,其他一些標簽值可能變為強制/可選。
現在,對於所有情況,我都制作了單獨的xsd,嘗試檢查各自的必填字段。 但是我如何告訴jaxb驗證xml應該使用哪個xsd?
<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>
也許是這樣的:
<bean id="contractUnmarshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
<property name="classesToBeBound">
<list>
<value>Class1</value>
<value>Class2</value>
</list>
</property>
<property name="schemas">
<list>
<value>Class1Schema</value>
<value>Class2Schema</value>
</list>
</property>
</bean>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.