Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Richard Hands
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3150
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm afraid its not possible with xml schmea.
You can try to see whether xsd:choice can help you. ?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic