XML Schema:使枚举属性值具有内容条件

时间:2022-10-02 17:18:29

I am trying to make an element's content conditional on an enumerated attribute. The content for each attribute will be completely different. For instance:

我试图使一个元素的内容以枚举属性为条件。每个属性的内容将完全不同。例如:

<?xml version="1.0" encoding="utf-8"?>
<foo type="bar">
    <bargress num="5"/>
    <bargress num="8"/>
</foo>

and

<?xml version="1.0" encoding="utf-8"?>
<foo type="kan">
    <kangress say="hi"/>
    <kangress say="all"/>
</foo>

would validate, but

会验证,但是

<?xml version="1.0" encoding="utf-8"?>
<foo type="kan">
    <bargress num="5"/>
    <bargress num="8"/>
    <kangress say="hi"/>
    <kangress say="all"/>
</foo>

would not.

不会。

Is this possible, and if so how would I go about it?

这是可能的,如果是这样,我该怎么做呢?

1 个解决方案

#1


1  

What you are describing is essentially "Conditional Type Assignment" which is one of the new features in XSD 1.1 (available today in Xerces and Saxon).

你所描述的基本上是“条件类型分配”,它是XSD 1.1中的新功能之一(今天在Xerces和Saxon中可用)。

The nearest you can get in XSD 1.0 is to rename your "type" attribute as xsi:type, and have it refer to the name of a complex type defined in your schema.

在XSD 1.0中最接近的是将“type”属性重命名为xsi:type,并让它引用模式中定义的复杂类型的名称。

#1


1  

What you are describing is essentially "Conditional Type Assignment" which is one of the new features in XSD 1.1 (available today in Xerces and Saxon).

你所描述的基本上是“条件类型分配”,它是XSD 1.1中的新功能之一(今天在Xerces和Saxon中可用)。

The nearest you can get in XSD 1.0 is to rename your "type" attribute as xsi:type, and have it refer to the name of a complex type defined in your schema.

在XSD 1.0中最接近的是将“type”属性重命名为xsi:type,并让它引用模式中定义的复杂类型的名称。