473,654 Members | 3,043 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Basic Schema subdivision question.

I am only just learning about schema basics. I am trying to understand
some fundamental principles about what can be specified within a schema.

If I define an enumerated list of values for an attribute in the root
element, is it then possible to limit which child elements may appear
depending on the value of that attribute? This enumerated attribute would
be used to specify a sub-type for this particular instance of a document.

For instance, if my document sub-type is "Table of Contents" then the
document may only contain designated "Table of Contents" type elements.
However, if the document sub-type is specified as "Index" then the only
type of elements that may appear are those associated with the "Index"
document sub-type. Basically, I want to have different sub-types of
documents that can only contain specific types of information but all
within the same root level doctype and schema.

I guess I could always accomplish this by simply specifying a limited set
of first level child elements specifying that only one of them may
appear. But I think I want to do this by using an attribute of the root
element instead.

I know I could also accomplish this by simply creating independent
schemas, each with their own independent doctype and possible elements.
However, I want to keep all of this within one schema.

Thanks for any assistance.
Jan 14 '07 #1
5 1720
Hello Grant,

Neither XML Schemas nor DTDs are limited to specifying a single element
that can be the root of a document. So you can define multiple global
elements in one schema and use any of them as the root element.
What you want is known co-occurrence constraint and is not supported by
XML Schema. However, there is a special attribute xsi:type (where xsi
points to the schema instance namespace:
http://www.w3.org/2001/XMLSchema-instance) that can be used to specify
inside the instance document the type of an element, that is you can
specify the type dynamically. So if you want to keep your initial idea
by all means this is the only possible solution: define the type of the
root element and then a couple of typed derived from that type than in
the instance specify the actua; type that you want to use for the root
element using xsi:type.

Best Regards,
George
---------------------------------------------------------------------
George Cristian Bina
<oXygen/XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com

Grant Robertson wrote:
I am only just learning about schema basics. I am trying to understand
some fundamental principles about what can be specified within a schema.

If I define an enumerated list of values for an attribute in the root
element, is it then possible to limit which child elements may appear
depending on the value of that attribute? This enumerated attribute would
be used to specify a sub-type for this particular instance of a document.

For instance, if my document sub-type is "Table of Contents" then the
document may only contain designated "Table of Contents" type elements.
However, if the document sub-type is specified as "Index" then the only
type of elements that may appear are those associated with the "Index"
document sub-type. Basically, I want to have different sub-types of
documents that can only contain specific types of information but all
within the same root level doctype and schema.

I guess I could always accomplish this by simply specifying a limited set
of first level child elements specifying that only one of them may
appear. But I think I want to do this by using an attribute of the root
element instead.

I know I could also accomplish this by simply creating independent
schemas, each with their own independent doctype and possible elements.
However, I want to keep all of this within one schema.

Thanks for any assistance.
Jan 15 '07 #2
In article <11************ **********@q2g2 000cwa.googlegr oups.com>,
ge****@oxygenxm l.com says...
So if you want to keep your initial idea
by all means this is the only possible solution: define the type of the
root element and then a couple of typed derived from that type than in
the instance specify the actua; type that you want to use for the root
element using xsi:type.

Thank you.
Jan 15 '07 #3
George, it took me a while to process all of this. I've been working on
my system and getting ready for the first day of the semester tomorrow.

In article <11************ **********@q2g2 000cwa.googlegr oups.com>,
ge****@oxygenxm l.com says...
Neither XML Schemas nor DTDs are limited to specifying a single element
that can be the root of a document. So you can define multiple global
elements in one schema and use any of them as the root element.
So, would I be correct in saying that all I need to do is list my 5
possible top elements and specify that only one can occur? I don't know
how that is done yet but I know it can be done for other elements within
a schema. Would I do it just the same as anywhere else?

What you want is known co-occurrence constraint and is not supported by
XML Schema. However, there is a special attribute xsi:type (where xsi
points to the schema instance namespace:
http://www.w3.org/2001/XMLSchema-instance) that can be used to specify
inside the instance document the type of an element, that is you can
specify the type dynamically.
This almost makes it sound as if you are saying that I can't do what you
just said I can do. Or are you saying that I can't do it the way I
originally thought of but can do it the way I just mentioned above? When
I went to the web site you listed I got a very terse page that simply
said you can't put attributes in "this namespace." But I didn't know
which namespace they were talking about.

So if you want to keep your initial idea
by all means this is the only possible solution: define the type of the
root element and then a couple of typed derived from that type than in
the instance specify the actua; type that you want to use for the root
element using xsi:type.
Now you have totally lost me. I think I might have confused you by using
the word "type" to refer to what I realize now is best called a "role."
All of my documents will be in the same namespace but I want some of them
to be used for different things. Each of these different uses would be a
different "role."

Or it could be that you are proposing a really elaborate trick to get a
parser to do what I want. I would like to avoid elaborate tricks because
they tend to break when standards get "cleaned up" at a later date.

Sorry for asking so many questions which are probably answered in most
books about XML Schemas. Can you believe there is not a single book on
the topic in this whole town. I am still waiting for the books I ordered
to arrive. Then I'll be cooking with gas.

P.S. I am going to give <oXygen/a try tomorrow. I'm thinking for $300
difference in price for the academic versions, I can at least give it a
try.
Jan 19 '07 #4
Hello Grant,

You can find below a couple of simple examples.
Suppose you have a schema that defines two global elements toc and
index, each containing toc1, toc2, tocn and, respectively, index1,
index2, indexn:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="toc">
<xs:complexType >
<xs:sequence>
<xs:element name="toc1"/>
<xs:element name="toc2"/>
<xs:element name="tocn"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="index">
<xs:complexType >
<xs:sequence>
<xs:element name="index1"/>
<xs:element name="index2"/>
<xs:element name="indexn"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>

Then both instance documents below will be valid against this schema:
<?xml version="1.0" encoding="UTF-8"?>
<toc>
<toc1></toc1>
<toc2></toc2>
<tocn></tocn>
</toc>

and

<?xml version="1.0" encoding="UTF-8"?>
<index>
<index1/>
<index2/>
<indexn/>
</index>

A namespace is just a string. The schema instance namespace is
http://www.w3.org/2001/XMLSchema-instance and it is used to qualify
some attributes with special meaning for XML Schema like
noNamespaceSche maLocation, schemaLocation, type, nil. Now suppose you
want the same root element, let's say someRoot and its content should
be either toc1, toc2, tocn or index1, index2, indexn depending on an
attribute value. The only possiblity with XML schema is to use xsi:type
as the attribute, thus specifying the type of the someRoot root
element.

For instance you can have the following instance documents:

<?xml version="1.0" encoding="UTF-8"?>
<someRoot xmlns:xsi="http ://www.w3.org/2001/XMLSchema-instance"
xsi:type="tocTy pe">
<toc1></toc1>
<toc2></toc2>
<tocn></tocn>
</someRoot>

and

<?xml version="1.0" encoding="UTF-8"?>
<someRoot xmlns:xsi="http ://www.w3.org/2001/XMLSchema-instance"
xsi:type="index Type">
<index1/>
<index2/>
<indexn/>
</someRoot>

that will be valid against the following schema
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="someRoot" type="xs:anyTyp e"/>
<xs:complexTy pe name="tocType">
<xs:sequence>
<xs:element name="toc1"/>
<xs:element name="toc2"/>
<xs:element name="tocn"/>
</xs:sequence>
</xs:complexType>
<xs:complexTy pe name="indexType ">
<xs:sequence>
<xs:element name="index1"/>
<xs:element name="index2"/>
<xs:element name="indexn"/>
</xs:sequence>
</xs:complexType>
</xs:schema>

Hope these help,
George
---------------------------------------------------------------------
George Cristian Bina
<oXygen/XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com

Jan 19 '07 #5
In article <11************ **********@q2g2 000cwa.googlegr oups.com>,
ge****@oxygenxm l.com says...
Hope these help,
Yes! they really do. You give some of the best answers I have ever read
on usenet. Thank you very much.
Jan 19 '07 #6

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

Similar topics

0
5058
by: Antony | last post by:
Hi there, firstly thank you for thinking about this problem of mine. This is a long message because I want to put all the facts (the XML and the schema) to try to get a solution from you helpful readers of the newsgroup. Here is my problem. I have defined the following XML schema. <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <xsd:simpleType name="currencySymbol">
7
2663
by: Andrei Ivanov | last post by:
This happend again, but now, postgresql tells me where it happens: pg_dump: SQL command failed pg_dump: Error message from server: ERROR: did not find '}' at end of input node pg_dump: The command was: select (select usename from pg_user where usesysid = datdba) as dba, pg_encoding_to_char(encoding) as encoding, datpath from pg_database where datname = 'dc' pg_dumpall: pg_dump failed on database "dc", exiting
2
1652
by: Gary McGill | last post by:
I'm finding the XmlSchema object model very hard to follow :-( I've figured out by trial and error how to do most things I need, but this one has me beat. Suppose my schema has a simple type defined as follows: <xs:simpleType name="abc"> <xs:restriction base="xs:string"> <xs:enumeration value="A" />
2
6924
by: PeterW | last post by:
I have an xml file from which I want to generate an xsd schema and at a later stage a cs class. The xml file has a mix of defined namespaces and also an empty namespace. These are defined as follows: <silcn:silcn xmlns:silcn='http://silcn.org/200309' xmlns='http://xmlprobe.com/200312'> it contains an element <report> off the root and also a separate <Silcn:report> again off the root.
6
3618
by: CT | last post by:
Lets say you have a query select * from db2.employees; here what is db2 - is it schema name, database name or table creator name? Also, does it make a difference of notation when you are in pc world or mainframe zos world. I am using v8 on pc and v7 on zos.
4
2614
by: cmc | last post by:
I need some clarification to help me understand the DB2 strucure more. The questions are about "implicit schema" 1. This is a very interest concpet that DB2 let every user to create new schema (as this is part of the PUBLIC group privilege - if I am not wrong). From a practical stand point, what is the application of such concept. 2. Suprisingly, if the schema is an implicitly created, everyone else can create objects in it too. What...
6
5111
by: DH | last post by:
I have a VERY basic question about figuring database size. I've inherited a database which is generally similar to this basic one: Item, Red, Blue, Green, Yellow (text), (int),(int),(int),(int) box, 1,0,0,2 hat, 0,0,0,1 car, 3,0,0,0 This format leads to a lot of zeros in the rows which take up a lot of
7
1205
by: CSharpguy | last post by:
I'm coding my first business web app in .NET 2.0 and its only a read only web app. I'm just pulling data from the database and allowing users to filter the data in the grids by using dropdowns. I've been reading and seen how you can drag and drop the controls and bind them that way, though I'm used to coding using a business layer and datalayer. So my question is since this is only a view only site, would it make more sense to use the new...
4
1226
by: Tony Johansson | last post by:
Hello! I know this might not be the appropriate forum for xml question. But xml is so important for .NET I hope my basic question can be answered in this forum. I just wonder does every xml document have a XSD schema or XDR schema ? Is it possible to say that the purpose for schema is to have a definition for syntax.
0
8285
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
8814
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
8706
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
8475
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
7304
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
5621
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
4149
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4293
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2709
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.