Creating a 'flexible' XML schema

后端 未结 2 1271
眼角桃花
眼角桃花 2021-01-13 05:01

I need to create a schema for an XML file that is pretty flexible. It has to meet the following requirements:

  1. Validate some elements that we require to be pres
2条回答
  •  南方客
    南方客 (楼主)
    2021-01-13 05:25

    I was thinking about this problem a lot today. I was considering how hard this xs:all rule makes it for XML databases to store documents that have unstructured "CMS" like data, while also validating the data.

    Then it occurred to me that XHTML allows for very flexible arrangements of nested elements in whatever order you need to mark a page up with.

    So here's an excerpt from the XHTML 1.1 schema:

      
        
          
          
          
          
          
        
      
    
      
        
      
    
      
        
          
        
      
    
      
      
        
          
          
          
          
          
          
          
          
          
        
      
    
      
        
          
          
          
          
          
          
        
      
    

    They essentially nest choices of groups, recursively. I imagine the person that wrote this is living out the rest of their days in a secure institution receiving forced medication several times a day.

    I hope this helps. I think this illustrates how super-flexi schemas are 'really' done in XSD 1.0.

    Edit - it works! You can make a 'master' group of all the other groups and use this example ListItem element definition to allow continuously nested elements in any order. Ensure ListItem is also included within a group so the recursion works.

      
        
          
            
          
        
      
    

    So my any.mix group looks like this:

      
              
          
          
          
                
        
      
    

    And each of those "class" groups contain yet more choices of groups, and so on and so on until they eventually hit the elements, the leaf level actual tags if you like.

    The groups themselves should not have circular references; the 'trick' is in the unbounded occurrences of the any.mix group, i.e. its a tree of choices with an unlimited root choice.

    Luke

提交回复
热议问题