473,325 Members | 2,805 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,325 software developers and data experts.

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 1702
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**********************@q2g2000cwa.googlegroups. com>,
ge****@oxygenxml.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**********************@q2g2000cwa.googlegroups. com>,
ge****@oxygenxml.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
noNamespaceSchemaLocation, 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="tocType">
<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="indexType">
<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:anyType"/>
<xs:complexType name="tocType">
<xs:sequence>
<xs:element name="toc1"/>
<xs:element name="toc2"/>
<xs:element name="tocn"/>
</xs:sequence>
</xs:complexType>
<xs:complexType 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**********************@q2g2000cwa.googlegroups. com>,
ge****@oxygenxml.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
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...
7
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...
2
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...
2
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...
6
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...
4
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...
6
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)...
7
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....
4
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.