Solved

How to define XSD conditionally depending on another element?

Posted on 2014-04-16
5
462 Views
Last Modified: 2014-06-01
Hi,
How to define my XSD, if the value of <Action> element is 'Update', <UpdateReason> element should NOT be blank.

possible values of <Action> tag are New / Update / Delete. In case of 'Update' , <UpdateReason> should NOT be blank.

Can anyone help me please?
0
Comment
Question by:GouthamAnand
  • 4
5 Comments
 
LVL 60

Accepted Solution

by:
Geert Bormans earned 500 total points
ID: 40005231
That is a co-occurence constraint.

That can not be modelled in XSD1.0
If you need to use XSD1.0, then you need to embed schematron rules
most parsers support schematron embedding one way or another

XSD1.1 has assertions,
If you parser supports XSD1.1 you can use assertions
Can you verify XSD1.1 support?
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 40005321
Here is an example XSD1.1

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"
    xmlns:vc="http://www.w3.org/2007/XMLSchema-versioning" vc:minVersion="1.1">
    <xs:element name="root">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="Action">
                    <xs:simpleType>
                        <xs:restriction base="xs:string">
                            <xs:enumeration value="New"/>
                            <xs:enumeration value="Update"/>
                            <xs:enumeration value="Delete"/>
                        </xs:restriction>
                    </xs:simpleType>
                </xs:element>
                <xs:element name="UpdateReason"/>
            </xs:sequence>
            <xs:assert test="not(Action = 'Update') or normalize-space(UpdateReason)"/>
        </xs:complexType>
    </xs:element>
</xs:schema>

Open in new window

0
 

Author Closing Comment

by:GouthamAnand
ID: 40006767
Thanks a lot. I am not using XSD1.1
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 40006955
OK, that is a disappointment then
- you could consider embedding schematron assertions (most parsers allow that, put the schematron assertions in their own namespace in the annotation)
- you could consider schematron validation after schema validation (that is for instance how Python supports that)
- or you could have a simple reporting XSLT to tell you wrong or right
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 40103467
Hi,
How did that work for you?
Maybe you could reconsider using XSD1.1, most parsers did implement at least the assertion bit
0

Featured Post

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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 …
The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

679 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