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

Simple Question - Simple Answer?

Hello,

Maybe you know howto. I want to have an element which takes a
subelement. Depending on an attribute within this subelement, a second
subelement may have different attributes allowed:

001 <Service>
002 <Header Kind="1"/>
003 <Input Data="asdasd"/>
004 </Service>
005 <Service>
006 <Header Kind="2"/>
007 <Input User="me" App="main"/>
008 </Service>

How can I specify that in an XML Schema? I tried the following:

001 <xsd:complexType name="service">
002 <xsd:choice minOccurs="1" maxOccurs="1">
003 <xsd:element name="Service" type="kind1"/>
004 <xsd:element name="Service" type="kind2"/>
005 </xsd:choice>
006 </xsd:complexType>
007
008 <xsd:complexType name="kind1">
009 <xsd:sequence>
010 <xsd:element name="Header" type="header1"/>
011 <xsd:element name="Input" type="input1"/>
012 </xsd:sequence>
013 </xsd:complexType>
014
015 <xsd:complexType name="kind2">
016 <xsd:sequence>
017 <xsd:element name="Header" type="header2"/>
018 <xsd:element name="Input" type="input2"/>
019 </xsd:sequence>
020 </xsd:complexType>
021
022 <xsd:complexType name="header1">
023 <xsd:attribute name="Kind" use="required"
type="header1Att"/>
024 </xsd:complexType>
025
026 <xsd:simpleType name="header1Att">
027 <xsd:restriction base="xsd:string">
028 <xsd:pattern value="1"/>
029 </xsd:restriction>
020 </xsd:simpleType>
031
032 <xsd:complexType name="input1">
033 <xsd:attribute name="Data" use="required"
type="xsd:string"/>
034 </xsd:complexType>
035
036 <xsd:complexType name="header2">
037 <xsd:attribute name="Kind" use="required"
type="header2Att"/>
038 </xsd:complexType>
039
030 <xsd:simpleType name="header2Att">
041 <xsd:restriction base="xsd:string">
042 <xsd:pattern value="2"/>
043 </xsd:restriction>
044 </xsd:simpleType>
045
046 <xsd:complexType name="input2">
047 <xsd:attribute name="User" use="required"
type="xsd:string"/>
048 <xsd:attribute name="App" use="required"
type="xsd:string"/>
049 </xsd:complexType>

However, doublicate definitions of an element of the same name seem
not to be allowed, which makes sense. But I don't know how to define
this sort of structur e then. Any ideas?

Thanks in advance
Daniel Frey
Jul 20 '05 #1
4 2531


Daniel Frey wrote:

Maybe you know howto. I want to have an element which takes a
subelement. Depending on an attribute within this subelement, a second
subelement may have different attributes allowed:


W3C XML schema doesn't allow you to model such a restriction (that is
attribute of one element defining attributes of another element).

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 20 '05 #2
Ok, I'd like to make a slight different document structure

001 <Service Kind="1"/>
002 <Input Data="asdasd"/>
003 </Service>
004 <Service Kind="2"/>
005 <Input User="me" App="main"/>
006 </Service>

I put the kind into the parent element. What I'd like here is that the
kind is defining which attributes of the *contained* element are
allowed. Is this possible (by the W3C standard)?

Thanks
Daniel
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #3


Daniel Frey wrote:
Ok, I'd like to make a slight different document structure

001 <Service Kind="1"/>
002 <Input Data="asdasd"/>
003 </Service>
004 <Service Kind="2"/>
005 <Input User="me" App="main"/>
006 </Service>
What you have there is not even well-formed, it has no root element, the
<Service Kind="1"/> is an empty tag but later on you have a closing tag
</Service>.
I put the kind into the parent element. What I'd like here is that the
kind is defining which attributes of the *contained* element are
allowed. Is this possible (by the W3C standard)?


It is certainly allowed by the XML specification to have different
attributes.
Neither DTD nor W3C schema allow you to put restrictions on the type of
attributes of one element based on the value of the parent element.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 20 '05 #4
You are totally right with the closing element. And thanks for ansering
the question so fast!

I think then I'll have to switch definitively to another structure like
that:

001 <ServiceA>
002 <Input Data="asdasd"/>
003 </ServiceA>
004 <ServiceB>
005 <Input User="me" App="main"/>
006 </ServiceB>

I think in this case this is the only solution to validate it against a
schema.

Thanks
Daniel
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #5

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

Similar topics

9
by: Dr. Paul Bremmer, PhD | last post by:
Dear Access experts: Access is returning the error, "Expression too complex," despite only entering an absurdly simple math function. Is there a way to simplify this any further, or perhaps...
1
by: number1.email | last post by:
Hello, I have a simple Web Page Questionairre in which questions are read from a database, and the user can indicate the correct answer via either a radio input control or a dropdown list. The...
3
by: manleytim | last post by:
Hello, I am pretty new to JavaScript. I was trying one of the examples in my Text Book JavaScript Third Edition and for some reason I can't seem to get the windows alert popups to say if the...
1
by: Synapse | last post by:
Hello... We were asked to create a simple calculator program in our C++ subject by using loops only. i have a problem in creating a loop in the multiplication and division operation so please can...
2
by: dave | last post by:
Hi, I have searched for the answer for this error message without success. I have seen the question many times though:) I create an ASP.NET project (VS 2005, C#), and use a very simple .mdf...
7
by: javedna | last post by:
Hi guys Ive got a simple problem, im designing an online questionnaire and on submission the coding that I have used to validate whether a user has filled in all the questions is supposed to...
30
by: galiorenye | last post by:
Hi, Given this code: A** ppA = new A*; A *pA = NULL; for(int i = 0; i < 10; ++i) { pA = ppA; //do something with pA
1
by: DennyLoi | last post by:
Hi there I am writing a simple while loop which terminates on the condition that a certain value is found, as follows std::string question = q.quest().que(); std::string answer =...
7
by: CSharper | last post by:
Yesterday I had a heated discussion with my colleagues on what is a data centric application and having business logic in sql. I have group of people who wants to include all the business logic in...
17
by: Chris M. Thomasson | last post by:
I use the following technique in all of my C++ projects; here is the example code with error checking omitted for brevity: _________________________________________________________________ /*...
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: 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?
1
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...
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:
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...
0
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...
0
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,...

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.