Best practice Questions

J

jlamb77

Hi,

I am in the process of creating a schema definition to validate some
XML data that will look like the following:

ProductA

SubProductA
SubProductB
SubProductC

ProductB

SubProductX
SubProductY
SubProductZ

Now I would like if possible to create a simple type called say
"Product" which has Enum content of:

Enum:"ProductA"
Enum:"ProiductB"
......
......

Then also have another simple type for the "SubProduct" with it's Enum
values as follows:

Enum:"SubProductA"
Enum:"SubProductB"
EnumL:"SubProductX"
......


I am struggling in deciding the best way to structure the complex Type
so that the Structure is enforcing the fact that SubProductX can only
be a SubProduct of ProductB......

I would like the flexability to be able to simply add a new
ProductType and enforce the relevant subtypes allowed to be detailed
with them.

Am fairly new to XSD (3 Weeks in) Any help much appreciated.
 
A

Andy Dingley

I am in the process of creating a schema definition to validate some
XML data that will look like the following:

Just don't. This isn't an appropriate concept to try and validate
with schema.


Sadly it's too difficult to spend the full time explaining, given
today's workload. Briefly though:

Schema / DTD validates XML _structure_ and not 'data' content. If you
follow your approach here, you're pushing 'data' items into the
structure by using them to generate element names. This would also
permit DTD / Schema validation ("permit", not "make it easy") of your
data rules. However this is also a use of XML that's usually a bad
idea -- you've implemented something that's changeable in practice
(product structure) and nailed it down with something that really
implies long-term stability (XML Schema).

A better approach would be a simple XML Schema based on just <Product>
as an element and keeping ProductA, ProductB etc. well away from this.
This does make Schema-based validation difficult though and starts to
look like a task for OWL instead. Even then, it's still easy to get to
a stage of complexity where it becomes impossible to validate
automatically. Better than fluid element names though.
 
J

Joe Kesselman

I am struggling in deciding the best way to structure the complex Type
so that the Structure is enforcing the fact that SubProductX can only
be a SubProduct of ProductB......

That sounds like it ought to be something enforced by your application
code, at least as much because it will change dynamically over time
based on other tables of product relationships as because it'll be a
pain to do in schemas. (You don't want to have to change the schema when
you introduce a new product.)

Schemas are used to define the structure of a language. What you say
with the language is a separate question.

Use the schema system to define the structure of your documents, and
reasonable ranges for their values... but for nontrivial applications,
don't assume it's the only check that will be performed. Your
applications will have to continue applying semantic checks if you want
to make sure the document means something reasonable.


(By analogy: A schema for English would conclude that "colorless green
ideas sleep furiously" is a perfectly reasonable statement, because all
the words are valid and the sentence structure is acceptable. The fact
that it's nonsense has to be dealt with at another level.)
 
J

jlamb77

That sounds like it ought to be something enforced by your application
code, at least as much because it will change dynamically over time
based on other tables of product relationships as because it'll be a
pain to do in schemas. (You don't want to have to change the schema when
you introduce a new product.)

Schemas are used to define the structure of a language. What you say
with the language is a separate question.

Use the schema system to define the structure of your documents, and
reasonable ranges for their values... but for nontrivial applications,
don't assume it's the only check that will be performed. Your
applications will have to continue applying semantic checks if you want
to make sure the document means something reasonable.

(By analogy: A schema for English would conclude that "colorless green
ideas sleep furiously" is a perfectly reasonable statement, because all
the words are valid and the sentence structure is acceptable. The fact
that it's nonsense has to be dealt with at another level.)

Thanks very much for your responses i'll take that on board.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,999
Messages
2,570,244
Members
46,839
Latest member
MartinaBur

Latest Threads

Top