這是一個後續的問題上:Eclipse的錯誤 「沒有資源類型指定爲」
How to set restriction on XSD for id attributes
我使用Eclipse。我創建的答案代碼XSD文件,我得到了這3個錯誤:使用XSD驗證OK
error: Error: No resource type specified (at 'xpath' with value '@id'). fsm.xsd /test/res/xml line 24 Android AAPT Problem
error: Error: No resource type specified (at 'xpath' with value '@toState'). fsm.xsd /test/res/xml line 32 Android AAPT Problem
error: Error: No resource type specified (at 'xpath' with value '@fromState'). fsm.xsd /test/res/xml line 28 Android AAPT Problem
的XML測試文件與XMLSchema的情況下,即使有3所提到的錯誤。
我想知道這些錯誤是否只是Eclipse中的一個小故障,或者是否有其他我需要定義的東西來擺脫它們。
XSD的源代碼:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified"
attributeFormDefault="unqualified">
<xs:element name="FSM">
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs="unbounded" name="state">
<xs:complexType>
<xs:attribute name="id" type="xs:unsignedByte" use="required"/>
<xs:attribute name="name" type="xs:string" use="required"/>
</xs:complexType>
</xs:element>
<xs:element name="transition">
<xs:complexType>
<xs:attribute name="fromState" type="xs:unsignedByte" use="required"/>
<xs:attribute name="toState" type="xs:unsignedByte" use="required"/>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
<xs:key name="PKStates">
<xs:selector xpath="state"/>
<xs:field xpath="@id"/>
</xs:key>
<xs:keyref name="FKTransitionToStatesFrom" refer="PKStates">
<xs:selector xpath="transition"/>
<xs:field xpath="@fromState"/>
</xs:keyref>
<xs:keyref name="FKTransitionToStatesTo" refer="PKStates">
<xs:selector xpath="transition"/>
<xs:field xpath="@toState"/>
</xs:keyref>
</xs:element>
</xs:schema>
XML測試文件:
<?xml version="1.0" encoding="utf-8"?>
<FSM xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="fsm.xsd">
<state name="S1" id="1"/>
<state name="S2" id="2"/>
<state name="S3" id="3"/>
<transition toState="1" fromState="2"/>
</FSM>
再次感謝。順便說一下,我從狀態id屬性中刪除了'use = required',因爲密鑰PKStates似乎強制該屬性存在。 – ilomambo
@ilomambo,我不會刪除它;它可能看起來是多餘的,但請考慮某些支持XSD的處理器忽略鍵/ keyref,因此您會發現自己遇到了一些麻煩......互操作性第一... –
對不起,您的答案取消。事實證明,這不是一個配置問題,我發現一個旁路,我發佈在一個單獨的答案。所以爲了其他程序員的緣故,我必須標記旁路答案。 – ilomambo