473,796 Members | 2,875 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XML Schema: disjunctive attributes for element possible ?

Hello folks,

Short question: Is it possible to express with XML-Schema that for an
element some attributes may apear only disjunctivly (i.e. an element
<E> can either carry the attribute "a1" OR "a2", but never both of
them)?

Thanks in advance,

Puck.
Jul 20 '05 #1
2 1625


Gehirnloser Zombie wrote:
Short question: Is it possible to express with XML-Schema that for an
element some attributes may apear only disjunctivly (i.e. an element
<E> can either carry the attribute "a1" OR "a2", but never both of
them)?


I know one way to do that, by defining a base type and deriving two
types from and then use xsi:type on the instance data:

<?xml version="1.0" encoding="UTF-8"?>
<root xmlns:xsi="http ://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespace SchemaLocation= "test20040112Xs d.xml">
<element xsi:type="elTyp e1" a1="value" />
<element xsi:type="elTyp e2" a2="value" />
</root>
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

<xs:element name="root">
<xs:complexType >
<xs:sequence>
<xs:element ref="element" maxOccurs="unbo unded" />
</xs:sequence>
</xs:complexType>
</xs:element>

<xs:element name="element" type="elType" />

<xs:complexTy pe name="elType" />

<xs:complexTy pe name="elType1">
<xs:complexCont ent>
<xs:extension base="elType">
<xs:attribute name="a1" type="xs:string " />
</xs:extension>
</xs:complexConte nt>
</xs:complexType>

<xs:complexTy pe name="elType2">
<xs:complexCont ent>
<xs:extension base="elType">
<xs:attribute name="a2" type="xs:string " />
</xs:extension>
</xs:complexConte nt>
</xs:complexType>

</xs:schema>
I don't think you can do it without xsi:type.
--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 20 '05 #2
Thanks, although the need to specify the "xsi:type" in the XML is not
an acceptable solution for me.

Puck.
Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
2943
by: Jari Kujansuu | last post by:
I can successfully parse XML document using SAX or DOM and I can also validate XML document against schema. Problem is that my program should deal with user-defined schemas which means that when I parse some element from XML document I don't know until runtime the type of the element (it depends on the type used in user-defined schema). XML parser obviously validates that the value of the element is correct type but still I receive that...
4
1677
by: Andrew | last post by:
Antony (4:26 PM) : Hello all ! I have a problem with XML schema. My XML document which I need to be validated can be one of the following two types: 1st type is
0
1630
by: Olaf Meyer | last post by:
I'm wondering if I can also express uniquness constraints on attributes of objects that I have referenced from somewhere else. To be a bit more precise here a short and simple XML document. The "objects" have a key constraint on the id attribute, i.e. they need to be unique. The object-ref element may reference the previously defined objects and hence has a keyref constraint on the id attribute. I would now like to furhter restrict the...
1
1404
by: Alex Sab | last post by:
Hi, I have a XML structure where the element name can be chosen freely but the element attributes must be all of the same names. <Node> <AnyName1 Type="Single" Unit="" Comment="">0</AnyName1> <AnyName2 Type="Single" Unit="" Comment="">0</AnyName2> <AnyName3 Type="Single" Unit="" Comment="">0</AnyName3> <AnyName4 Type="Single" Unit="" Comment="">0</AnyName4> <AnyName5 Type="Single" Unit="" Comment="">0</AnyName5>
2
5087
by: Tarren | last post by:
Hi: The problem I am having is when I validate an xml file to a schema, it is erroring out every element. I think this has something to do with me defining/referencing the namespaces. I have searched on the net for a while, but am still confused. Thanks in advance for help. Below is the code I am working with. What am I not referencing/referencing incorrectly? ===================================
2
9237
by: Shailendra Batham | last post by:
Hello Gurus, I want to put some restrictions on my attribute tag in my XML Schema, anyone out there have any idea how to do that. here is my XML and the XML Schema <?xml version="1.0" encoding="utf-8"?> <Book ID="1000000000"> <Name>XML Basic</Name> <Comments>Whatever</Comments>
6
2592
by: Martin | last post by:
Hi, I have a xml file like the one below <?xml version="1.0" encoding="utf-8"?><e1 xmlns:e1="http://tempuri.org/Source1.xsd" e1:att1="1" e1:att2="2" e1:rest="345"/> If I try to create a schema for it with Visual Studio, I get the error "Failed to create a schema for this data file because:
1
19079
by: Mikus Sleiners | last post by:
I have a task to create xml document from c# code. I have example of that document should look like and also a xml schema. I wonder if i can use this xml schema somehow ? This is schema: <?xml version="1.0"?> <xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
0
2633
by: rautsmita | last post by:
hello friends , i am using to jdk6 and JAXB2.0, i have geomtry.xsd file i am trying to compile this file using jaxb but i got some error i.e.The particle of the type is not a valid restriction of the particle of the base this xsd file is valid as per w3c standard i am also providing error in detail and geometry.xsd file geometry.xsd <?xml version="1.0" encoding="UTF-8"?> <schema targetNamespace="http://www.opengis.net/gml"...
0
9527
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
10453
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...
1
10172
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
9050
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...
0
6785
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();...
0
5573
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4115
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
2
3730
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2924
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.