In the following example, test.xml
shows no IntelliJ problem but test2.xml
shows an Invalid id reference highlighting fooid
red.
Surprisingly, this is different to what happens with test3.xml
where also the root
elements are annotated with There is no ID/IDREF binding for IDREF 'fooid2'.
main.xsd
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:attributeGroup name="attributeGroup_foo">
<xs:attribute name="id" type="xs:ID" use="required"/>
</xs:attributeGroup>
<xs:complexType name="complexType_foo">
<xs:attributeGroup ref="attributeGroup_foo"/>
</xs:complexType>
<xs:attributeGroup name="attributeGroup_bar">
<xs:attribute name="idref" type="xs:IDREF" use="required"/>
</xs:attributeGroup>
<xs:complexType name="complexType_bar">
<xs:attributeGroup ref="attributeGroup_bar"/>
</xs:complexType>
<xs:complexType name="complexType_root">
<xs:sequence>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="root" type="complexType_root"/>
<xs:element name="foo" type="complexType_foo"/>
<xs:element name="bar" type="complexType_bar"/>
</xs:choice>
</xs:sequence>
</xs:complexType>
<xs:element name="root" type="complexType_root"/>
</xs:schema>
test.xml
<?xml version="1.0" encoding="utf-8"?>
<root
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xi="http://www.w3.org/2001/XInclude"
xsi:noNamespaceSchemaLocation="main.xsd">
<foo id="fooid"/>
<bar idref="fooid"/>
</root>
test1.xml
<?xml version="1.0" encoding="utf-8"?>
<root
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xi="http://www.w3.org/2001/XInclude"
xsi:noNamespaceSchemaLocation="main.xsd">
<foo id="fooid"/>
</root>
test2.xml
<?xml version="1.0" encoding="utf-8"?>
<root
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xi="http://www.w3.org/2001/XInclude"
xsi:noNamespaceSchemaLocation="main.xsd">
<xi:include href="test1.xml" parse="xml">
<xi:fallback/>
</xi:include>
<bar idref="fooid"/>
</root>
test3.xml
<?xml version="1.0" encoding="utf-8"?>
<root
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xi="http://www.w3.org/2001/XInclude"
xsi:noNamespaceSchemaLocation="main.xsd">
<xi:include href="test1.xml" parse="xml">
<xi:fallback/>
</xi:include>
<bar idref="fooid2"/>
</root>
I am wondering why the ID from test1 is not available in test2. Possibly this is an XY problem: maybe I am misusing XML/XSD and should solve my problem differently? What would be the best practice here?
My goal is basically to define parts of a bigger XML file in separate XML files and to include them to avoid code duplicates if e.g. some parts are imported multiple times into different other XML files (e.g. some basic part that is imported in 10 or so other xml files that then have nothing to do with each other). Parsing those XML files also currently works but I am not happy with the red highlighting.