这是一个后续问题:
我使用 Eclipse。我使用答案代码创建了一个 XSD 文件,但出现以下 3 个错误:
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
使用 xsd 的带有 XMLSchema-instance 的 XML 测试文件验证正常,即使存在上述 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>