XML schema construct for “any one or more of these elements but must be at least one”

后端 未结 3 1918
-上瘾入骨i
-上瘾入骨i 2020-12-03 17:06

I\'m trying to set up part of a schema that\'s like a \"Sequence\" where all child elements are optional, but at least one of the elements must be present,

3条回答
  •  广开言路
    2020-12-03 17:39

    @hurst,

    Unfortunately you have failed to understand the original question. Placing minOccurs="1" on the choice is satisfied automatically when ALL elements that have minOccurs="0" are contained as options.

    Thus you have failed to account for the "at least one" required by the original poster, because no elements correctly satisfies 1 occurrance of two completely optional elements.

    So far I am unable to find a solution to this as minOccur/maxOccur both relate to the group in which they are defined and DO NOT relate to an overall number of nodes. Nor can you use the choice element to define the same named element more than once or it becomes "ambiguous". I have seen some examples use references instead of elements of a specific type, but I believe this fails the microsoft XSD parser.

    
      
        
        
      
      
        
      
    
    

    Here you can see that either you have the first sequence (which MUST have Elem1 but may have Elem2 optionally), or you have the second sequence (which MUST have Elem2).

    Hence you now have "any one or more" of these 2 elements. Of course this gets exponentially more complex the more options you have as you need to provide additional choices for all possible combinations.

提交回复
热议问题