XML schemas with multiple inheritance

前端 未结 3 1867
孤城傲影
孤城傲影 2021-02-12 16:36

Is it possible to have multiple inheritance in XML schemas, if so how?

Example



 

        
3条回答
  •  栀梦
    栀梦 (楼主)
    2021-02-12 16:47

    Something that resembles multiple inheritance in some ways can be managed using named model group and named attribute groups; whether it resembles multiple inheritance in the way you want is something only you can tell.

    Suppose you have complex types Account (as shown above) and Customer, and you'd like complex type CreditCardAccount to inherit from each of them. As others have pointed out, you can't specify two base types in a complex type definition. But you can package the content model of the Account and Customer types into named model groups, and refer to the appropriate named group from the type definition.

    
      
        
        
      
    
    
    
      
        
        
        
        
      
    
    
    
      
        
      
    
    
    
      
        
      
    
    

    Then you can refer to both named groups from CreditCardAccount:

    
      
        
        
        
        
        
      
    
    

    An XSD validator will not regard the types Customer, Account, and CreditCardAccount as related in this case, which may or may not matter.

    Of course, a simpler approach would be to use elements as packages of information, and define elements Account, Customer, and CreditCardAccount, with CreditCardAccount containing (surprise) an Account element and a Customer element.

提交回复
热议问题