Solved

How to define XSD conditionally depending on another element?

Posted on 2014-04-16
5
456 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
xpath sql query 2008 8 58
XSLT -  replace invalid xml characters 15 46
TSQL XML Namespaces 7 21
PHP delete contents of file- before writing to it 6 17
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, …
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

790 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