views:

51

answers:

1

I'm working on a custom XML format that involves a formatted list of points. We would like to support multiple types of coordinates systems, such as Cartesian and Spherical. Can this be done?

Example:

<point type="cartesian">
<c1>5.0</c1>
<c2>5.6</c2>
<c3>9.1</c3>
</point>
<point type="spherical">
<c1>5.0</c1>
<c2>5.6</c2>
<c3>9.1</c3>
</point>

Where there are automatically bounds for the spherical coordinates keeping c1 positive, and c2,c3 in the range 0 to 2PI. While having no bounds for c1 through c3 in the cartesian version. If this can not be written as a Scheme, can I at least do it this way?

<point type="cartesian">
<c1 type="cartesian">5.0</c1>
<c2 type="cartesian">5.6</c2>
<c3 type="cartesian">9.1</c3>
</point>
<point type="spherical">
<c1 type="spherical">5.0</c1>
<c2 type="spherical">5.6</c2>
<c3 type="spherical">9.1</c3>
</point>

In this case I know I can enforce constraints on an element by it's type, but can I enforce a particular element to have the same type as it's parent?

I hope this is clear enough to get what I am trying to do here. I want to constrain the type of data the c1 through c3 types will accept by setting the type of the point element.

+3  A: 

No, this is not possible.

On the other hand, you can have sphericalPoint and cartesianPoint elements which extend point. Under some circumstances, you can restrict the types of the child elements, assuming they are a subset of the type of the parent elements. You can also add child elements which did not exist in the base type.

John Saunders
A job for schematron?
Nic Gibson
If the relatively low amount of support is ok with you, then I guess so.
John Saunders
When it comes down to it, if you can do XSLT you can do Schematron. That's generally been enough support for my purposes :)
Nic Gibson
I mean platform support. Is there a Schematron implementation for .NET, for instance? If there is, it's not from Microsoft, which would be an issue for some companies.
John Saunders