• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Query regarding xsd

 
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am trying to code an xsd to validate input xml to a tool. There is a requirement where an element is having two attributes and one of the attributes must definetely have a value

In above either ApiName or FlowName must have a value. How to specify this in xsd. Please advise.

Thanks,
Kranthi
 
kranthi chamarthi
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Can is use xs:choice in case of attributes to achieve above functionality or its only in case of element that we can use choice indicator. Please advise...
 
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

Can is use xs:choice in case of attributes to achieve above functionality...


No.

... or its only in case of element that we can use choice indicator.


It is.
 
kranthi chamarthi
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please let me know if there ia any way of accomplishing this in xsd...
 
g tsuji
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
But before knowing something, you have to say clearly what that something is precisely.

In above either ApiName or FlowName must have a value.


If any of them or either of them does not have a value, you want it appear as <name>="" or it just disappears from the element tag or something. What do you write the schema if you want some attribute has a value? Empty string seems to be a value as well, no?
 
kranthi chamarthi
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Only one of the two attributes which is having value should be declared on element. Suppose ApiName attribute is having value then Api tag will be as below

If FlowName is having value then

Blank value should not be considered as value. If none of ApiName or FlowName are specified with value then an error should be shown. Please advise.

Thanks
Kranthi

 
g tsuji
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
For non-empty requirement, we can do it via devices provisioned by schema v1.0. That is well-known. If you're not that in it, this is how amongst others.


Now, the problem of that if ApiName exists, FlowName does not and vice versa, it is known to be called co-occurrence constraints in the 10+ years of w3c schema literature. It is not a secret that v1.0 is not expressive enough to make such a constraint. Long time, this kind of constraints has to be done at the application level (ie, in the particular language of code, you do validation without the constraint and then in the code you check if they both exists etc...). Or else, you would have to use alternative schema such as Relaxng or Schematron.

Since some time already, you can now do it in a homogeneous platform of w3c schema with the use the schema v1.1, a development of v1.0. This is certain less well-known and supported. Xerce-j supports schema v1.1 such since or about v2.11.0... (in any case, use the latest version). To do that with w3c schema, you are then obliged to use v1.1 supported engine.

In schema v1.1, you can do it like this to give you an clear picture rather than just verbiage. However, you've have precised the content type of Api apart the attributes, let me support its content has a type apiBaseType. From it, you add the attributes with the constraint scripted like this.

If that is too involved, do thing at the application level as mentioned above.

ps Edition Original I just put [^\s]+. After reviewing the post, it is too restrictive. I edit the pattern to allow a more reasonable and less restrictive value range.
 
Get me the mayor's office! I need to tell him about this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic