XML架构使用属性不能出现在元素中
因此,当我将XML架构使用属性不能出现在元素中,xml,xsd,Xml,Xsd,因此,当我将use=“required”属性放入XML分配的模式中时,我得到以下消息: s4s att不允许:属性“use”不能出现在元素中 “元素” 这是什么意思?它似乎根本不会影响我的代码,并且这个赋值需要use属性 架构代码: <?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="Inve
use=“required”
属性放入XML分配的模式中时,我得到以下消息:
s4s att不允许:属性“use”不能出现在元素中
“元素”
这是什么意思?它似乎根本不会影响我的代码,并且这个赋值需要use属性
架构代码:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Inventory">
<xs:complexType>
<xs:sequence>
<xs:element name="Items" use="required">
<xs:complexType>
<xs:sequence>
<xs:element name="PartID" type="xs:ID" use="required"/>
<xs:element name="Part_Desc" type="xs:string" use="required"/>
<xs:element name="Price" type="xs:decimal" use="required"/>
<xs:restriction base="xs:decimal">
<xs:fractionDigits value="2"/>
</xs:restriction>
</xs:sequence>
<xs:attribute name="vendor_id" type="xs:int" use="required"/>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
下面是我的XML代码:
<?xml version="1.0" encoding="UTF-8"?>
<Inventory xsi:noNamespaceSchemaLocation="exam.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Items vendor_id="2">
<PartID>a101</PartID>
<Part_Desc>Keyboard</Part_Desc>
<Price>79.99</Price>
</Items>
<Items vendor_id="5">
<PartID>a404</PartID>
<Part_Desc>Wireless Mouse</Part_Desc>
<Price>59.99</Price>
</Items>
<Items vendor_id="3">
<PartID>a120</PartID>
<Part_Desc>2 GB USB Drive</Part_Desc>
<Price>18.99</Price>
</Items>
<Items vendor_id="8">
<PartID>c506</PartID>
<Part_Desc>24" Monitor</Part_Desc>
<Price>459.99</Price>
</Items>
</Inventory>
a101
键盘
79.99
a404
无线鼠标
59.99
a120
2 GB USB驱动器
18.99
c506
24英寸显示器
459.99
代码似乎仍然有效,没有错误。使用
属性仅对xs:attribute
元素有效
如果要指定元素是必需的或可选的,请使用minOccurs
属性
所需要素:
<xs:element name="PartID" type="xs:ID" minOccurs="1"/>
将Price
定义为小数部分有两位数字的十进制。谢谢,但现在当我在元素中取出use属性,并将其留空或放入minOccurs时,我收到一条消息,说xs:restriction是不允许的。但是,它似乎没有错误。我添加了一个关于如何使用restriction的解释
。我不知道您在使用什么进行验证,但只要模式本身无效(事实就是如此),验证程序就应该拒绝它,并且不对XML进行任何验证。再次感谢。我正在使用一个名为Editix的程序。免费下载XML编辑器。
<xs:element name="PartID" type="xs:ID" minOccurs="0"/>
<xs:element name="Price" minOccurs="1">
<xs:simpleType>
<xs:restriction base="xs:decimal">
<xs:fractionDigits value="2"/>
</xs:restriction>
</xs:simpleType>
</xs:element>