XSD allowing both simpleType and complexType content for same element?

后端 未结 2 1285
长情又很酷
长情又很酷 2020-12-21 13:57

I have a situation where I have different XMLs that will have different types of properties. Sometimes the element HEADER could have just a node or some XMLs co

2条回答
  •  太阳男子
    2020-12-21 14:32

    In XSD, you cannot allow both simple and complex content unless you're willing to have mix elements and text via mixed="true" (in this case Example 1 is not needed). You could then used XSD 1.1 assertions to exclude both from appearing simultaneously.

    
    
      
        
          
            
              
                
              
            
          
        
      
      
    
    
    

    However, you're swimming against the current here. Instead, accept that you really have two different entities with two different content models and name the different entities differently: SIMPLE_HEADER and COMPLEX_HEADER comes to mind. Then you can use xs:choice/maxOccurs="unbounded" on Details to allow simple and complex headers to be freely interspersed.

提交回复
热议问题