• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

XML Validation Query thrugh XSD

 
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

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

<Required_Fields>
<AccountNumber>
<UserName>
<AppName>
</Required_Fields>

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: 729
7
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!