File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes XML and Related Technologies and the fly likes xml schema, one element with multiple definitions depending on value of an attribute 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 "xml schema, one element with multiple definitions depending on value of an attribute" Watch "xml schema, one element with multiple definitions depending on value of an attribute" New topic
Author

xml schema, one element with multiple definitions depending on value of an attribute

Richard Hands
Greenhorn

Joined: Feb 25, 2004
Posts: 12
Hi,

I'm currently working on a project that takes the Raw XML and transforms it into a pseudo 'form' type XML, and i'm trying to write an XML Schema to validate that developers have written the transformation stylesheets to output the data in the correct format.

The question is, is there way in XML Schema to define essentially two (or more) definitions for the same element, dependant upon a given attribute in it. Therefore if type='text' then it must have attributes A and B and optionally can have attribute C & D, but if type='date' then it must have attribute X and can optionally have attribute Y & Z?

I'm relatively inexperienced as far as XML Schema's go and the way the data has been defined from stage one is thus

<table>
<row>
<field type="text" name="field1" value="bob" style="font-weight:bold;"/>
<field type="date" name="field2" format="datetime" validatepast="true" value="1973-07-27 16:34:00"/>
</row>
</table>

I get the feeling it might be something to do with <xs:attributeGroup> element but i can't seem to get it working correctly.

obviously this is a very cut down version and there's a host of other tags, but i've tried to keep it simple as it covers what's needed.
Balaji Loganathan
author and deputy
Bartender

Joined: Jul 13, 2001
Posts: 3150
I'm afraid its not possible with xml schmea.
You can try to see whether xsd:choice can help you. ?


Spritle Software Blogs
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: xml schema, one element with multiple definitions depending on value of an attribute