开发者

Can an XML Schema defined tag have different constraints based on data type?

开发者 https://www.devze.com 2022-12-16 18:42 出处:网络
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?

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 ca开发者_C百科n 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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号