?
Solved

How to define XSD conditionally depending on another element?

Posted on 2014-04-16
5
Medium Priority
?
570 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

Application Discovery Service in AWS

In the era of the cloud, customers migrating away from their existing on-premise infrastructure. This requires lots of planning, strategies, and effort to identify their existing resources and determine how best to migrate.  Datacenter migrations happen in four phases -

Question has a verified solution.

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

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…
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…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses
Course of the Month15 days, 2 hours left to enroll

771 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