473,390 Members | 1,246 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,390 software developers and data experts.

How can you specify co-dependent attributes in XSD?


Is there any way of specifying a pair of attributes that are both optional but if one is present the other must also be?

Thanks in advance.
Mar 11 '10 #1
3 5172
700 Expert 512MB
You can try to achieve this using abstract types and xsi:type attribute

Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.example.org/GolfCountryClub" xmlns:tns="http://www.example.org/GolfCountryClub">
  4.     <element name="osoby">
  5.         <complexType>
  6.             <sequence>
  7.                 <element name="osoba" type="tns:tagType"></element>                        
  8.             </sequence>
  9.         </complexType>
  10.     </element>    
  14.     <complexType name="tagType" abstract="true" />
  16.     <complexType name="tagWithAttr">
  17.            <complexContent mixed="true">
  18.               <extension base="tns:tagType">
  19.                  <attribute name="attr1" type="string" use="required"/>
  20.                  <attribute name="attr2" type="string" use="required"/>
  21.               </extension>
  22.            </complexContent>
  23.     </complexType>
  25.     <complexType name="tagWithoutAttr">
  26.            <complexContent mixed="true">
  27.               <extension base="tns:tagType">
  28.               </extension>
  29.            </complexContent>
  30.     </complexType>
  31. </schema>
valid xmls
Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <tns:osoby xmlns:tns="http://www.example.org/GolfCountryClub" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.example.org/GolfCountryClub GolfCountryClub.xsd ">
  3.   <osoba attr1="18" attr2="19" xsi:type="tns:tagWithAttr"/>
  4. </tns:osoby>
Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <tns:osoby xmlns:tns="http://www.example.org/GolfCountryClub" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.example.org/GolfCountryClub GolfCountryClub.xsd ">
  3.   <osoba xsi:type="tns:tagWithoutAttr"/>
  4. </tns:osoby>
nonvalid xmls
Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <tns:osoby xmlns:tns="http://www.example.org/GolfCountryClub" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.example.org/GolfCountryClub GolfCountryClub.xsd ">
  3.   <osoba attr1="18"  xsi:type="tns:tagWithoutAttr"/>
  4. </tns:osoby>

Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <tns:osoby xmlns:tns="http://www.example.org/GolfCountryClub" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.example.org/GolfCountryClub GolfCountryClub.xsd ">
  3.   <osoba attr1="18"  xsi:type="tns:tagWithAttr"/>
  4. </tns:osoby>
Is that ok for you?
Mar 14 '10 #2
Hi rski,

that's a good solution ... wish I had thought of it!!

However, we can't use it in this instance. We have written a system to process customer transmitted files conforming to a specific xsd that we provide. Our system is deployed and live and cannot be changed. This solution would require a code change.

Thanks though.
Mar 15 '10 #3
700 Expert 512MB
Is it possible for you to add some Relax-NG formulas into the xsd file?
Mar 15 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

by: Jim Cochrane | last post by:
I just google-searched this group and could not find any references to this. I'm trying to figure out how to specify a three-part header with html. For example, left part ...
by: Jeremy Collins | last post by:
Hi all, How do I specify "noshade" as the style for an <HR> element in my style sheet? hr { height: 1px; color: #EEEEEE; ???? }
by: Tony Marston | last post by:
The code <a href="..." target="_blank">...</a> will not validate as XHTML STRICT because of the 'target' tag, so how do I achieve the same result by moving it to a CSS file? I cannot find anything...
by: Mark | last post by:
Hi all, I have a query which returns 56 results every time. 1 field of the query contains the results of an expression where 55 will contain decimal points and 1 will be a whole number. Is there a...
by: chrisn | last post by:
Hi, Does anyone know a good way to specify the DOCTYPE in code? (Using C#, ASP.net) Thanks in advance, Chris Needham
by: Chris Ianson | last post by:
Hi all, Well having found this group to be a fountain of knowledge I have another question. And hey, no worries if you don't know or don't want to answer, please ignore this. Is there a way...
by: Lucky | last post by:
hi guys, i got an error while i was migrating one of the webproject developed in 1.1 to 2.0. i got error in one dll reference in global.asax. it says "The type 'Ims.Tmpc.Global' is...
by: Chris Tomlinson | last post by:
Hi, is there any way to specify the sequence in which images load on a web page? More specifically, here is what we need to achieve: Image1 starts loading first and the browser does not...
by: suki | last post by:
Hi! Does anyone know, where i can specify a channel of my sound card to play a mci-video? Now, i play a video and the sound is on the on-board sound-output. But i have a soundcard with 4 sound...
by: phiberoptick | last post by:
I am looking for a way to specify which IP or interface to use as the source when calling fsockopen on a server with multiple IP's. Any help or direction would be much appreciated. -Ronan
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.