[英]XML Schema Use Attribute Cannot Appear in Element
因此,當我將use ="required"
屬性放入我的架構中進行XML分配時,我收到以下消息:
s4s-att-not-allowed:屬性'use'不能出現在元素'element'中。
這是什么意思? 它根本不會影響我的代碼,並且此賦值需要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>
代碼似乎仍然有效,沒有錯誤。
use
屬性僅對xs:attribute
元素有效。
如果要指定元素是必需的或可選的,請使用minOccurs
屬性。
要素:
<xs:element name="PartID" type="xs:ID" minOccurs="1"/>
元素可選:
<xs:element name="PartID" type="xs:ID" minOccurs="0"/>
請注意,默認情況下, minOccurs
為1
,而默認情況下, use
是optional
。
UPDATE
restriction
的使用需要(簡單)類型的定義。 這個:
<xs:element name="Price" minOccurs="1">
<xs:simpleType>
<xs:restriction base="xs:decimal">
<xs:fractionDigits value="2"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
將Price
定義為小數部分的2位數。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.