我有这样的元素
<xsd:element name="Car" type="carType"/>
<xsd:complexType name="carType">
<xsd:complexContent>
<xsd:extension base="basicType">
<xsd:attribute name="motor" type="xsd:IDREF" use="required"/>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
当前文件中的电机元件时,工作正常。
<Car id="car1" motor="motor1"/>
<Motor id="motor1"/>
但是当我想从另一个文件中import
运动元素
<beans:bean:import resource="motors.conf.xml"/>
Intellij Idea说Invalid id reference
,当我运行程序时,我得到一个异常
There is no ID/IDREF binding for IDREF
可能我做错了什么?或者可能xsd:IDREF
等于ref local
,因此我无法将其与导入一起使用?
答案 0 :(得分:2)
我是对的,xsd:IDREF
等于参考本地。
关于xsd:IDREF
MSDN Creating Valid ID, IDREF...
你可以在这里看到为什么它等于 -
<xsd:element name="ref">
<xsd:annotation>
<xsd:documentation><![CDATA[
Defines a reference to another bean in this factory or an external
factory (parent or included factory).
]]></xsd:documentation>
</xsd:annotation>
<xsd:complexType>
<xsd:complexContent>
<xsd:restriction base="xsd:anyType">
<xsd:attribute name="bean" type="xsd:string">
<xsd:annotation>
<xsd:documentation><![CDATA[
The name of the referenced bean.
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
**<xsd:attribute name="local" type="xsd:IDREF">**
<xsd:annotation>
<xsd:documentation><![CDATA[
The name of the referenced bean. The value must be a bean ID and thus can
be checked by the XML parser. This is therefore the preferred technique
for referencing beans within the same bean factory XML file.
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="parent" type="xsd:string">
<xsd:annotation>
<xsd:documentation><![CDATA[
The name of the referenced bean in a parent factory.
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
</xsd:restriction>
</xsd:complexContent>
</xsd:complexType>
</xsd:element>
它是元素bean元素ref
的描述。我们知道,我们只能将<ref local>
用于当前XML文档中的元素。