I’m trying to create an xsd schema that will validate a map with an unknown depth of nodes.
(In the schema below, i would like mapnode to contain, among other elements, more mapnodes.)
This requires recursion that starts below the root node.
Neither of the two methods described here seem to work for me: http://publib.boulder.ibm.com/infocenter/db2luw/v9r5/index.jsp?topic=%2Fcom.ibm.db2.luw.xml.doc%2Fdoc%2Fc0051286.html
with the schema below, i get this error:
src-resolve: Cannot resolve the name ‘mapnode’ to a(n) ‘element declaration’ component.
<?xml version="1.0" encoding="utf-16"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" version="1.0" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="knowledgemap">
<xs:complexType>
<xs:sequence>
<xs:element name="mapdata">
<xs:complexType>
<xs:all>
<xs:element name="title" type="xs:string"/>
<xs:element name="version" type="xs:string"/>
<xs:element name="author" type="xs:string"/>
<xs:element name="authorid" type="xs:string"/>
<xs:element name="width" type="xs:positiveInteger"/>
<xs:element name="height" type="xs:positiveInteger"/>
<xs:element name="xpos" type="xs:positiveInteger"/>
<xs:element name="ypos" type="xs:positiveInteger"/>
<xs:element name="scalefactor" type="xs:float"/>
<xs:element name="mapid" type="xs:string"/>
<xs:element name="beehivedata">
<xs:complexType>
<xs:sequence>
<xs:element name="maxresults" type="xs:positiveInteger"/>
<xs:element name="upiproduct" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="upiproduct" type="xs:string"/>
<xs:element name="upiversion" type="xs:string"/>
<xs:element name="upilanguage" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="styledata">
<xs:complexType>
<xs:sequence>
<xs:element name="nodelevel" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="level"/>
<xs:element name="width"/>
<xs:element name="height"/>
<xs:element name="fontsize"/>
<xs:element name="fontcolor"/>
<xs:element name="fontweight"/>
<xs:element name="strokecolor"/>
<xs:element name="strokewidth"/>
<xs:element name="linkcolor"/>
<xs:element name="linkhighlight"/>
<xs:element name="colorunexplored"/>
<xs:element name="colorexplored"/>
<xs:element name="colorshadow"/>
<xs:element name="iconsize"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:all>
</xs:complexType>
</xs:element>
<xs:element name="map">
<xs:complexType>
<xs:sequence>
<xs:element name="mapnode">
<xs:complexType>
<xs:sequence>
<xs:element name="nodedata">
<xs:complexType>
<xs:sequence>
<xs:element name="title" type="xs:string"/>
<xs:element name="description" type="xs:string"/>
<xs:element name="xpos" type="xs:integer"/>
<xs:element name="ypos" type="xs:integer"/>
<xs:element name="nodeid" type="xs:string"/>
<xs:element name="level" type="xs:positiveInteger"/>
<xs:element name="parent" type="xs:string"/>
<xs:element name="localconnection" type="xs:string"/>
<xs:element name="parentconnection" type="xs:string"/>
<xs:element name="covericon" type="xs:string"/>
<xs:element name="activesocket" type="xs:string" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="contentitem" maxOccurs="unbounded">
<xs:complexType>
<xs:all>
<xs:element name="title" type="xs:string"/>
<xs:element name="contentid" type="xs:string"/>
<xs:element name="description" type="xs:string"/>
<xs:element name="type" type="xs:string"/>
<xs:element name="size" type="xs:string"/>
<xs:element name="col" type="xs:positiveInteger"/>
<xs:element name="row" type="xs:positiveInteger"/>
<xs:element name="contenturl" type="xs:string"/>
<xs:element name="contenticon" type="xs:string"/>
<xs:element name="contentdata" type="xs:string" minOccurs="0"/>
</xs:all>
</xs:complexType>
</xs:element>
<xs:element ref="mapnode" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
To define a recursive structure, you will need to make the node that refers to itself (or if there is a cycle, one of the nodes in the cycle) into a global element declaration. When you use ref=”name”, it must refer to a global element – one declared as a child of the xs:schema element.