473,836 Members | 1,510 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XML Schema question

Hi--I am having a problem designing a schema to fit my XML data, and I'm
hoping that someone can help. Essentially, I have a schema in mind and two
target vocabularies for it, where one vocabulary is a subset of the other. I
will describe one part of the schema to give you an idea of what my problem
is.

The "big" schema calls for 0 or more selector elements, each containing a
(required) name attribute and simple character data, as follows:

<selector name="wakka">fo o</selector>

The "small" schema calls for 1 or more selector elements with a name of
"key", followed by 0 or more selector elements with any value for the name
attribute:

<selector name="key">esti mate</selector>

<selector name="key">summ ary</selector>

<selector name="custom1"> low-priority</selector>

As you can see, the small schema is a subset of the large schema.

My problem is that I can't find a way to define a parent element than can
describe the sequence of selector elements required by the small schema.
I've looked at redefinition, substitution groups, and other tricks for
making a schema open-ended. The problem is that they all require me to write
something like the following within a complex type definition:

<xsd:sequence >

<xsd:element maxOccurs="unbo unded" minOccurs="1" name="selector"
type="selectorK eyType"/>

<xsd:element maxOccurs="unbo unded" minOccurs="0" name="selector"
type="selectorT ype"/>

</xsd:sequence>

....where selectorKeyType and selectorType are defined as follows:

<xsd:complexTyp e name="selectorT ype">

<xsd:simpleCont ent>

<xsd:extensio n base="xsd:token ">

<xsd:attribut e name="name" type="xsd:NCNam e"/>

</xsd:extension>

</xsd:simpleConte nt>

</xsd:complexType >

<!-- ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ -->

<xsd:complexTyp e name="selectorK eyType">

<xsd:simpleCont ent>

<xsd:restrictio n base="selectorT ype">

<xsd:attribut e fixed="key" name="name" type="xsd:NCNam e"/>

</xsd:restriction >

</xsd:simpleConte nt>

</xsd:complexType >

The Xerxes parser reminds me that multiple elements with the same name must
have the same type:

[Message:E cos-element-consistent: Error for type '<ignore --gw>'. Multiple
elements with name 'selector', with different types, appear in the model
group. SystemID:file:/C:/xml/misc/schema-experiments/exper3/exper.xsd,
Line:35, Column:34, Offset:-1]

Of course, I could write my own code that would validate a given XML file
has been valid under the little schema, but the differences between the big
and little schemas are considerable. I could also describe the constrained
selector element using a slightly different name--cselector, for
example--but that would more or less negate the original design: namely,
that custom elements are distinguished from "official" elements only by the
value of the name attribute.

Is there a way to do what I want to do? Or is the inability of the XML
Schema to handle this situation an indication that what I am trying to do is
a Bad Thing? Thanks.

--gw
Jul 20 '05 #1
1 2728

"Gregg Williams" <gr****@NOSPAMp ubspace.com> wrote in message
news:vk******** ****@corp.super news.com...
Hi--I am having a problem designing a schema to fit my XML data, and I'm
hoping that someone can help. Essentially, I have a schema in mind and two
target vocabularies for it, where one vocabulary is a subset of the other. I will describe one part of the schema to give you an idea of what my problem is.

The "big" schema calls for 0 or more selector elements, each containing a
(required) name attribute and simple character data, as follows:

<selector name="wakka">fo o</selector>

The "small" schema calls for 1 or more selector elements with a name of
"key", followed by 0 or more selector elements with any value for the name
attribute:

<selector name="key">esti mate</selector>

<selector name="key">summ ary</selector>

<selector name="custom1"> low-priority</selector>
Can't do this. Elements with the same name in a sequence must have the same
type.

And (reading ahead a bit) you already know this! The Xerces parser told you
so.

Redesign your data model (which looks like a good idea in this case) or use
a more expressive schema language, like RELAX NG.

Bob Foster
As you can see, the small schema is a subset of the large schema.

My problem is that I can't find a way to define a parent element than can
describe the sequence of selector elements required by the small schema.
I've looked at redefinition, substitution groups, and other tricks for
making a schema open-ended. The problem is that they all require me to write something like the following within a complex type definition:

<xsd:sequence >

<xsd:element maxOccurs="unbo unded" minOccurs="1" name="selector"
type="selectorK eyType"/>

<xsd:element maxOccurs="unbo unded" minOccurs="0" name="selector"
type="selectorT ype"/>

</xsd:sequence>

...where selectorKeyType and selectorType are defined as follows:

<xsd:complexTyp e name="selectorT ype">

<xsd:simpleCont ent>

<xsd:extensio n base="xsd:token ">

<xsd:attribut e name="name" type="xsd:NCNam e"/>

</xsd:extension>

</xsd:simpleConte nt>

</xsd:complexType >

<!-- ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ -->

<xsd:complexTyp e name="selectorK eyType">

<xsd:simpleCont ent>

<xsd:restrictio n base="selectorT ype">

<xsd:attribut e fixed="key" name="name" type="xsd:NCNam e"/>

</xsd:restriction >

</xsd:simpleConte nt>

</xsd:complexType >

The Xerxes parser reminds me that multiple elements with the same name must have the same type:

[Message:E cos-element-consistent: Error for type '<ignore --gw>'. Multiple elements with name 'selector', with different types, appear in the model
group. SystemID:file:/C:/xml/misc/schema-experiments/exper3/exper.xsd,
Line:35, Column:34, Offset:-1]

Of course, I could write my own code that would validate a given XML file
has been valid under the little schema, but the differences between the big and little schemas are considerable. I could also describe the constrained
selector element using a slightly different name--cselector, for
example--but that would more or less negate the original design: namely,
that custom elements are distinguished from "official" elements only by the value of the name attribute.

Is there a way to do what I want to do? Or is the inability of the XML
Schema to handle this situation an indication that what I am trying to do is a Bad Thing? Thanks.

--gw

Jul 20 '05 #2

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

Similar topics

0
5065
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">
4
2944
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...
7
2677
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
6937
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.
4
2299
by: bibsoconner | last post by:
Hi, I hope someone can please help me. I'm having a lot of trouble with schema files in .NET. I have produced a very simple example that uses "include" to include other schema files. It all works with SPY, but when I pick "Validate Schema" from the .NET 2003 menu, it fails with message: "Type XType is not declared." As I hinted at in my subject line, I suspect that it has to do with including another schema multiple times.
4
2634
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...
1
20773
by: drb | last post by:
Hi, Newbie question #2 - hope that's OK! I'm trying to create a WSDL file using one or more XSD schema files. While WSDL.exe doesn't seem to support the XSD "import" function, if I include a single huge XSD schema file on the command line input to WSDL.exe, I can essentially achieve the desired result. (So, first question: is it true that WSDL.exe does not support *any* kind of <wsdl:import ...> or <xsd:import...> function?)
1
1946
by: brucepickford001 | last post by:
Hi, I have a not simple problem. I want the following XML to be schema valid <PopulationDemographic> <PersonName>Joe Blogs</PersonName> <Age>2</Age> <Category>baby</Category> </PopulationDemographic>
0
2267
by: jrhitokiri | last post by:
QUESTION 1: I'm trying to create a room reservation system for school using wicket and MySQL, and I'm a bit confused with this one. I've already created the user database and rooms database. My question is how do I create a schema that accepts both repeating and non-repeating schedules? example (repeating): I can reserve a room for class at 9:00am - 12:00pm every Monday and Thursday, from June - October of 2009. How do I represent this in...
0
9825
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9671
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
10854
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
10257
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
9387
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
6981
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
5829
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4022
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3116
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.