• 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

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

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
author and deputy
Posts: 3150
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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. ?
 
This is my favorite tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic