How to create a schema for an unordered list of XML nodes, with occurrence constraints

前端 未结 3 1652
生来不讨喜
生来不讨喜 2020-12-10 12:05

Given an XML layout like this, I\'m trying to create a XSD schema to validate it.


  
  
  
          


        
3条回答
  •  無奈伤痛
    2020-12-10 12:19

    Update: In XSD 1.1m some of the constraints on all-groups have been lifted. See the answers here and here.

    Not a simple one but seems doable. Difficult part here is that Schema definitions must be deterministic. Approach I used was to visualize the problem by drawing a finite state automata of it and then to write a regular expression that corresponded that automata. It is not at all as complicated as it might sound. Still, using some other validation system would have likely provided simpler answer.

    I have done some testing but missing out some special cases is easy. Please comment if you spot an error.

    ...and here is the code:

    
    
        
    
        
            
                
                    
                
            
        
    
        
            
                
                
                    
                        
                        
                        
                        
                            
                            
                        
                    
                    
                        
                        
                            
                            
                        
                        
                            
                            
                                
                                
                            
                        
                    
                
            
        
    
    
    

提交回复
热议问题