?
Solved

How to define XSD conditionally depending on another element?

Posted on 2014-04-16
5
Medium Priority
?
672 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
5 Comments
 
LVL 60

Accepted Solution

by:
Geert Bormans earned 2000 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
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. 
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

650 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