2013-04-30 62 views
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> 

回答

0

也许这样的事情?:

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