aspose file tools*
The moose likes XML and Related Technologies and the fly likes Query regarding xsd Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Query regarding xsd" Watch "Query regarding xsd" New topic
Author

Query regarding xsd

kranthi chamarthi
Ranch Hand

Joined: May 08, 2007
Posts: 95
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

Joined: May 08, 2007
Posts: 95
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...
g tsuji
Ranch Hand

Joined: Jan 18, 2011
Posts: 547
    
    3
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

Joined: May 08, 2007
Posts: 95
Please let me know if there ia any way of accomplishing this in xsd...
g tsuji
Ranch Hand

Joined: Jan 18, 2011
Posts: 547
    
    3
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

Joined: May 08, 2007
Posts: 95
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

Joined: Jan 18, 2011
Posts: 547
    
    3
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Query regarding xsd