XSD: How to derive a simpletype both to add a attribute to it and to restrict the acceptable value of it

前端 未结 2 832
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-15 01:49

for example To validate the following element:

 100 

The constraint I want on the text

2条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-15 02:21

    Extending a simple type with attributes

    Inspired by Petru Gardea's answer to XSD custom type with attribute and restriction, I have come up with a solution that should work for you. Your element must be a complexType extending the restricted simpleType with an attribute:

    
    
        
            
            
        
    
    
    
    
        
            
                
                
                    
                
            
        
    
    

    Extending multiple types with the same set of attributes

    In addition, if you want to extend multiple types with the same set of attributes, you could use the xsd:attributeGroup as suggested in C. M. Sperberg-McQueen's answer to XSD: Adding attributes to strongly-typed “simple” elements:

    
     
        
        
    
    
    
    
        
            
            
        
    
    
    
    
        
            
                
                
                    
                
            
        
    
    

    This would validate the following xml element:

    100
    

提交回复
热议问题