• 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 ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

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
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: 734
7
  • 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.
 
I will suppress my every urge. But not this shameless plug:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic