XSD - mutual exclusion based on selection (if/else)

Posted on 2009-02-23
Last Modified: 2012-05-06
What I want to do in my XSD is have a choice of elements based on a previously selected element value to ensure that validation takes place properly (as there is only a single, special case for the element which I want to create).

The logic would be something like:

<A>value1</A> then only <B> can follow
<A>value2</A> then only <C> can follow
<A>value2</A> then only <C> can follow
<A>valueN</A> then only <C> can follow

So the "code" section would contain three valid schema definitions.

How would I do this?






  <C>some other data type</C>




  <C>some other data type</C>


Open in new window

Question by:revof11_
    1 Comment
    LVL 60

    Accepted Solution

    This is a co-occurence constraint and can not be expressed by W3C Schema 1.0
    There is an assert extension to schem (in W3C SChema 1.1) but as far as I know that is only supported by Saxon as of now.
    You should use a layered validation approach with your schema in combination with

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    Automatically Generate Documents from XML database 10 31
    xsl to xslt 2 30
    C# List error (C# experts help!) 9 52
    RSS Feed Validation 2 40
    The Problem How to write an Xquery that works like a SQL outer join, providing placeholders for absent data on the outer side?  I give a bit more background at the end. The situation expressed as relational data Let’s work through this.  I’ve …
    Introduction In my previous article ( I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now