Conditional required elements in an XSD

后端 未结 1 1005
予麋鹿
予麋鹿 2020-12-14 23:11

I have a requirement for an xml schema which accepts either a request with the customer or with the customer id. If the customer Id is 0 then we need the customer data, if

1条回答
  •  隐瞒了意图╮
    2020-12-14 23:39

    This is possible in XSD 1.1; below is a simplified example, which assumes MainApplicant and WhereSigned are mandatory when CustomerId is equal to zero.

    
    
    
        
            
                
                
                
                
                
                
                
                
                
                
                
                
            
            
        
        
        
        
          
    
    

    Minimum valid XML, when CustomerId is zero:

    
        UserID1
        asodasqZX==
        0
        
        
    
    

    When CustomerId is non-zero, then this is the minimum XML:

    
        UserID1
        asodasqZX==
        1
    
    

    The conditional can be easily controlled (see the @test expression); add regular XSD constraints as needed (e.g. if your CustomerId needs to be greater than or equal to zero, then make it nonNegativeInteger, etc.)

    0 讨论(0)
提交回复
热议问题