我们如何将属性放入XML模式的元素中?
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.google.com"
xmlns="http://www.google.com"
elementFormDefault="qualified">
<xsd:element name ="students">
<xsd:simpleContent>
<xsd:extension base="xsd:string">
<xsd:attribute name="IDNUMBER" type="integer" use="required"/>
</xsd:extension>
</xsd:simpleContent>
<xsd:complexType>
<xsd:sequence>
<xsd:element name ="guy">
<xsd:complexType>
<xsd:sequence>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
我不太明白为什么它不起作用。我试着把属性和东西放在一起,但是我得到了所有类似的错误,这些错误似乎与实际错误没有任何关系。之前,我收到Error3033:内容无效。预期的是(注释?,(元素选择)*)。现在,我得到了别的东西。我们如何将属性放入XML模式的元素中?
您在<xsd:element>
标记中同时使用<xsd:simpleContent>
和<xsd:complexType>
。这是不可能的,无论是你的新元素<students>
有简单文本或者是复杂类型。见3.3.2 XML Representation of Element Declaration Schema Components:
内容:(注释?((简单类型|复杂类型)?,替代*,(唯一|键| keyref)*))
决定要使用(其中一个simpleType或ComplexType)并使用(其中之一)。
我们可以在复杂类型中使用复杂类型吗? – user2089523 2013-04-06 16:00:54
@ user2089523:不知道这个问题,但它被定义为**复杂类型元素**当然可以有其他的元件,其也定义为** **复杂类型。所以我会说,你可以有“复杂类型内的复杂类型” – Progman 2013-04-06 17:33:31
“*现在,我还有其他东西*” - 继续,给我们一个线索。 – 2013-04-06 07:17:43