473,608 Members | 2,410 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How can you specify co-dependent attributes in XSD?

2 New Member
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 5185
rski
700 Recognized Expert Contributor
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
tskelly
2 New Member
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 Recognized Expert Contributor
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
3255
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 center part right part For old troffists, this is what the .tl construct does. But how would it be done in html? I tried <div align = left>left part</div> <div align = center> ..., which almost worked, except each part is on...
2
2497
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
77500
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 which allows me to specify 'target=' on an anchor tag. -- Tony Marston http://www.tonymarston.net
4
5314
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 way to set the criteria of this field so that only the result containing the whole number is returned? Many thanks, Mark
2
1455
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
6257
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 to change the timeout of a tooltip AKA alt text over a picture? Normally the text appears for about 5 seconds then vanishes, but I'd like it to stay indefinitely on a specific picture. (It's a photo with a description of the photo).
1
6771
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 ambiguous: it could come from assembly 'C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\tmpc\0645d1b5\4ea8c73e\App_Code.h0ihzjo3.DLL' or from assembly
27
2261
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 continue through the HTML until Image1 has loaded COMPLETELY. When Image1 is done, Image2 BEGINS loading. When Image2 is 100% done, only then does Image 3 begin... and so on...
1
1517
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 outputs and i want to specify where to play the sound.. Can anyone help me?
2
5634
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
8010
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8501
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8483
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8157
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8349
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6820
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6015
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5479
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2477
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.