473,395 Members | 1,335 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,395 software developers and data experts.

How can you specify co-dependent attributes in XSD?

Hi,

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 5174
rski
700 Expert 512MB
You can try to achieve this using abstract types and xsi:type attribute

xsd
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">
  3.  
  4.     <element name="osoby">
  5.         <complexType>
  6.             <sequence>
  7.                 <element name="osoba" type="tns:tagType"></element>                        
  8.             </sequence>
  9.         </complexType>
  10.     </element>    
  11.  
  12.  
  13.  
  14.     <complexType name="tagType" abstract="true" />
  15.  
  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>
  24.  
  25.     <complexType name="tagWithoutAttr">
  26.            <complexContent mixed="true">
  27.               <extension base="tns:tagType">
  28.               </extension>
  29.            </complexContent>
  30.     </complexType>
  31. </schema>
  32.  
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>
  5.  
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>
  5.  
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>
  5.  

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>
  5.  
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
rski
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

12
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 ...
2
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; ???? }
6
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...
4
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...
2
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
11
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...
1
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...
27
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...
1
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...
2
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
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
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
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
Oralloy
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,...
0
jinu1996
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 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.