我有这样的元素

<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,所以我不能在import中使用它?

最佳答案

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

关于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文档中的元素。

关于java - IDREF属性只能具有本地ID值吗?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/14827334/

10-09 20:00