Solved

How to define XSD conditionally depending on another element?

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

743 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

14 Experts available now in Live!

Get 1:1 Help Now