Cannot resolve the name X to an element declaration component in a recursive xml schema
16,265
If you wish to refer to an element, it must be declared as top level. You can have both root
and node
referring to the same element using:
<xs:element ref="node" />
That's why your second example works. You can use this schema:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
<xs:element name="node">
<xs:complexType>
<xs:sequence>
<xs:element ref="node" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="root">
<xs:complexType>
<xs:sequence>
<xs:element ref="node" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Author by
Felix D.
Updated on June 30, 2022Comments
-
Felix D. almost 2 years
I'm just beginning working with XML schemas. I'm creating a simple schema and I don't understand why I get an error while trying to implement a simple recursive element. I'm sure it's totally trivial.
Here I get the following error: E [Xerces] src-resolve: Cannot resolve the name 'node' to a(n) 'element declaration' component.
<?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"> <xs:element name="root"> <xs:complexType> <xs:sequence> <xs:element name="node"> <xs:complexType> <xs:sequence> <xs:element ref="node" /> </xs:sequence> </xs:complexType> </xs:element> </xs:sequence> </xs:complexType> </xs:element> </xs:schema>
And here, not having the
root
element, I don't get the error...<?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"> <xs:element name="node"> <xs:complexType> <xs:sequence> <xs:element ref="node" /> </xs:sequence> </xs:complexType> </xs:element> </xs:schema>
I am totally mesmerized 0_0. How can I achieve this?