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

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">foo</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">estimate</selector>

<selector name="key">summary</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="unbounded" minOccurs="1" name="selector"
type="selectorKeyType"/>

<xsd:element maxOccurs="unbounded" minOccurs="0" name="selector"
type="selectorType"/>

</xsd:sequence>

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

<xsd:complexType name="selectorType">

<xsd:simpleContent>

<xsd:extension base="xsd:token">

<xsd:attribute name="name" type="xsd:NCName"/>

</xsd:extension>

</xsd:simpleContent>

</xsd:complexType>

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

<xsd:complexType name="selectorKeyType">

<xsd:simpleContent>

<xsd:restriction base="selectorType">

<xsd:attribute fixed="key" name="name" type="xsd:NCName"/>

</xsd:restriction>

</xsd:simpleContent>

</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 2681

"Gregg Williams" <gr****@NOSPAMpubspace.com> wrote in message
news:vk************@corp.supernews.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">foo</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">estimate</selector>

<selector name="key">summary</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="unbounded" minOccurs="1" name="selector"
type="selectorKeyType"/>

<xsd:element maxOccurs="unbounded" minOccurs="0" name="selector"
type="selectorType"/>

</xsd:sequence>

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

<xsd:complexType name="selectorType">

<xsd:simpleContent>

<xsd:extension base="xsd:token">

<xsd:attribute name="name" type="xsd:NCName"/>

</xsd:extension>

</xsd:simpleContent>

</xsd:complexType>

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

<xsd:complexType name="selectorKeyType">

<xsd:simpleContent>

<xsd:restriction base="selectorType">

<xsd:attribute fixed="key" name="name" type="xsd:NCName"/>

</xsd:restriction>

</xsd:simpleContent>

</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
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...
4
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...
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: 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...
4
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...
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...
1
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...
1
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>...
0
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...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
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)...
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.