Is it possible to restrict elements to a max occur in a “choice” block?

前端 未结 4 942
野的像风
野的像风 2021-01-19 12:49

I need to solve the following problem.

//pseudo algorithm

  • you have four elements: elm1, elm2, elm3, elm4
  • elm1 occurs 0-2 times
  • elm2 o
4条回答
  •  面向向阳花
    2021-01-19 13:15

    If your n values not too big and you're desperate you can make a content model that accounted for every possible combination, but that grows complex exponentially.

    The best solution is to use a tool that supports XML Schema 1.1 (such as Xerces or Saxon), which relaxes restrictions on all group occurrence values. From section G.1.3 of the spec:

    1. Several of the constraints imposed by version 1.0 of this specification on all-groups have been relaxed:

      a. Wildcards are now allowed in all groups.

      b. The value of maxOccurs may now be greater than 1 on particles in an all group. The elements which match a particular particle need not be adjacent in the input.

      c. all groups can now be extended by adding more members to them.

    Failing that, the general XML Schema 1.0 solution is to specify a relaxed model in the schema (no limits on the element occurrences) and then enforce the constraints you care about in another layer, which might be custom code or XSLT, for instance.

提交回复
热议问题