0

To most of you this question may be repeatable. But, i have searched a lot on the website but could not find a solution which fits my requirements. For example consider a XML like:

<root>
<A/>
<B/>
<C/>
<D/>
<D/>
</root>

the objective is to achieve a schema which can allow A,B and C only once and they are mandatory and D multiple time(that is optional). In the earlier post , i have seen solutions using Choice, but if choice is used here then a XML like this would be validated-

<root>
<A/>
<D/>
</root>

The above XML is wrong since mandatory elements B and C are omitted if CHOICE is used. I can only use XSD 1.0. Any help to solve this issue is highly appreciated.

Thanks

  • 1
    Does this help: http://stackoverflow.com/q/37969890/290085 – kjhughes Jun 22 '16 at 23:05
  • This does not help me. I have already explained in my question that how it is different from the existing solution on this website. I can not use wrappers and XSD1.1. And also choice will not work for this.Please go through my question once more. – Machine_leaning_9 Jun 22 '16 at 23:47
  • If you exclude all previous offerings as not applying to your situation, then you cannot use XSD 1.0 to express your constraint. It's that simple. Your question is less special than you think it is. – kjhughes Jun 23 '16 at 01:12

1 Answers1

1

Welcome to Stack Overflow. You say you searched "a lot" on the web site, but you seem to have had very bad luck. A quick search for either "xs:all" or "xsd:all" produces a number of questions that look just like yours. The ones I wrote down before getting bored were:

This one may also be worth consulting:

I hope you have better luck finding useful search terms, next time!

Community
  • 1
  • 1
C. M. Sperberg-McQueen
  • 24,596
  • 5
  • 38
  • 65
  • Hi, Thanks for sharing these links. i have gone through most of these links during my search. Most of the solutions recommended are like to use XSD1.1 (which i can not ), use choice (I already mentioned that why I can no use that as it does not fit my requirements) and in some case wrapping the elements, wrapping will not work because it will force me to make changes in the the XML file. So I am looking for a solution based on above conditions. unfortunately, these links does not help me. Thanks for your time. – Machine_leaning_9 Jun 22 '16 at 23:36
  • Then you're hoping beyond reason for a solution that does not exist. – kjhughes Jun 22 '16 at 23:47
  • The questions give a pretty good survey of the alternative ways to satisfy all or a subset of the requirements you mention. If you MUST use XSD 1.1 and you WILL NOT modify the XML, then your remaining option is to write a deterministic content model that accepts all and only the sequences you wish to accept. It's not too hard: six possible orders for A, B, and C, interleaved with D. There are examples in some of the answers cited, I expect, or in others. – C. M. Sperberg-McQueen Jun 23 '16 at 03:28