W3C home > Mailing lists > Public > xmlschema-dev@w3.org > April 2008

RE: XML schema help for an XML document

From: Stan Kitsis <Stan.Kitsis@microsoft.com>
Date: Mon, 28 Apr 2008 14:46:19 -0700
To: Manikandan Thangavelu <Manikandan_T1@verifone.com>, "xmlschema-dev@w3.org" <xmlschema-dev@w3.org>
Message-ID: <03A576FA617C6544AEF9B925FB2B4E2A21E4B9CCAA@NA-EXMSG-C114.redmond.corp.microsoft.com>

In general, the answer is that XSD 1.0 spec doesn't support this type of constraints.  However in your specific case (if you only have two attributes), you can enforce it using the following uniqueness constraint:

  <xs:element name="Menuitem">
      <xs:attribute name="ID" />
      <xs:attribute name="ApplicationPath" />
    <xs:key name="uniqueAtt">
      <xs:selector xpath="."/>
      <xs:field xpath="@ID|@ApplicationPath"/>

Note: I don't think that this use of the key constraint was intended by the XSD spec authors and there are people on this list who will warn you against using it to enforce a co-occurrence constraint.

Stan Kitsis
Microsoft Corporation

From: xmlschema-dev-request@w3.org [mailto:xmlschema-dev-request@w3.org] On Behalf Of Manikandan Thangavelu
Sent: Sunday, April 27, 2008 9:03 AM
To: xmlschema-dev@w3.org
Subject: XML schema help for an XML document

From:   Manikandan Thangavelu
Sent:   27 April 2008 21:27
To:     'xmlschema-dev-request@w3.org'
Subject:        XML schema help for an XML document

Hi All,

I am trying to develop an XML schema for an XML file which is used to build the UI for an application.
I have an issue in it.In one of my XML tags there are two attributes out of which one is mandatory and presence of both are mutually exclusive.If one of those attibbute is present, then the other should not.Follwing is the sample of my XML

    <Menuitem name="_Contents" ID= "ID_CONTENTS" Description="Help Contents." />
    <Menuitem name="_Index" ID= "ID_INDEX" Description="Help Index." />
    <Menuitem name="_Search" ID= "ID_SEARCH" Description="Help Search.." />
    <Menuitem name="_About Me" ID= "ID_ABOUT_Me" Description="VeriCentre version information and Add-on(s) installed." />

    <Menuitem name="_Notepad" ApplicationPath="C:\Windows\notepad.exe" Description="Opens the notepad application."/>
    <Menuitem name="Adobe" ApplicationPath="C:\Program Files\Adobe\Adobe.exe" Description="Open Adobe"/>

Among the attributes for Menuitem either "ID" or "ApplicationPath" is mandatory.If "ID" is there, then "ApplicationPath" should not be and if "ApplicationPath" is there, then "ID" should not be.

How can I develop a schema for this case?

Thanks in Advance,
Received on Tuesday, 29 April 2008 02:46:43 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 23:15:46 UTC