1

我有这样的元素

<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:IDREFequals ref local,所以我不能将它与 import 一起使用?

4

1 回答 1

2

我是对的,xsd:IDREF等于 ref local。

关于xsd:IDREF MSDN 创建有效 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>

它是 element bean element 的描述ref。正如我们所知,我们只能使用<ref local>当前 XML 文档中的元素。

于 2013-02-12T10:36:05.257 回答