Can I create an XSD schema that places an attribute on all complex types?

前端 未结 4 951
日久生厌
日久生厌 2021-01-06 14:02

I would like to create an XSD that defines an attribute which can be placed on elements from other schemas, or elements that are not in any schema. For example, the schema

4条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-06 14:42

    You can redefine schema, extending them however you like. In this way, you can modify the definitions of an existing schema without actually changing the file. BUT IT WON'T WORK FOR YOUR EXAMPLE as given, because one can't redefine elements (only complexTypes, etc. see http://www.w3.org/TR/xmlschema-1/#element-redefine). Therefore, I've broken your example into explicit complexTypes, so they are exposed for redefinition.

    RedefineOtherSchema.xsd:

              
    
             
    
          
        
          
            
                    
            
          
        
      
    
    

    OtherSchema:

    
      
    
        
          
            
          
        
    
        
          
        
    
    

    MySchema: (unchanged)

    
      
    
    

    Why ? The redefinition must be an extension (or restriction) of the existing type - that's how it modifies the previous definition. Extension must be in (I believe).

    Why ? You can't define things in more than one namespace in a xsd (there is only one "targetNamespace"). But you can get around this by importing a definition from another xsd (then you've not "defining" it). [is there is another way?]

    HTH :-)

提交回复
热议问题