• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Devaka Cooray
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
  • paul wheaton
  • Jeanne Boyarsky
  • Tim Cooke
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown

XML Validation Query thrugh XSD

Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

We have a requirement where we need to make atleast one of the elements in a group as required. Please refer below:


So, in the above XML structure, my requirement is that atleast one of AccountNumber, UserName, AppName must be supplied by the user. So, we need to validate it using XSD. Can you please suggest if there is any way to validate it through XSD? We need to create the XSD for this.

Thanks in advance!
Ranch Hand
Posts: 734
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Within w3c schema language, you put cardinality facet minOccurs="0" to all of the elements AccountNumber, UserName and AppName making them all optional. But then it leaves one edge case of all of them being absent. However small and however so commonly conceivable use case it may be, w3c schema language v1.0 is not expressive enough for this edge case. If you are using v1.0, you have not much choice but to add a little routine, after validation being done, in your application code to further control the existence of at least one child element of Required_Field element. If the control is negative, throw an exception for the purpose.

In w3c schema language v1.1, a whole class of cases previously cannot be handled in v1.0 including this one can be done in a homogeneous fashion all inside the schema. The support of v1.1 is expanding and improving over time. If you are not yet ready for that, do what I have suggested above.
It is no measure of health to be well adjusted to a profoundly sick society. -Krishnamurti Tiny ad:
a bit of art, as a gift, the permaculture playing cards
    Bookmark Topic Watch Topic
  • New Topic