【发布时间】:2010-07-07 16:16:09
【问题描述】:
让我们看看我的测试.xsd:
<!-- lot of stuff... -->
<xsd:element name="root">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="target:child"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="child">
<xsd:complexType>
<xsd:attribute name="childAttribute" type="myType"/>
</xsd:complexType>
</xsd:element>
<!-- lot of stuff... -->
好吧,一切都很好。只有一个问题:我的“子”元素没有类型!我不知道如何给元素一个类型。我试过了:
<xsd:element name="child" type="xsd:myType2">
<xsd:complexType>
<xsd:attribute name="childAttribute" type="myType"/>
</xsd:complexType>
</xsd:element>
或与
<xsd:element name="root">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="target:child" type="xsd:myType2"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
但它不会工作。总是有错误信息: "元素 'child' 不能同时具有 type 属性和 simpleType/complexType 类型 child[xml]]]"
我该如何解决这个问题?我的意思是如果没有类型,验证器将不允许这样的 xml:
你好世界
一个属性只允许一个空子
有人知道吗? 谢谢!
【问题讨论】:
标签: xml validation schema xsd