Finding root element..

Hello all..


I'm writting a utility that will create a simple XHTML form based on an 
XML schema.  Currently I'm adding an empty <root> element in the 
<appinfo> to mark an element as the root element.  So far this has 
served me well because I have also created all the XSD's that are used 
for this util.  But I would like to remove that dependancy now.


The only way I can think of locating the root element in *most* XSDs is 
to iterate through a nodelist of global elements and check for a parent 
element for each until I find one without.

There are at least two occations where this can fail.

1. recursive references ie:
	<xs:element name="foo">
		<xs:complexType>
			<xs:sequence>
				<xs:element ref="bar"/>
			</xs:sequence>
		</xs:complexType>
	</xs:element>
	<xs:element name="bar">
		<xs:complexType>
			<xs:sequence>
				<xs:element ref="foo"/>
			</xs:sequence>
		</xs:complexType>
	</xs:element>

2. orphaned elements (not inteded to be root, but have no parent).

Has anybody come up with a fail proof way to find the root element in 
*any* XSD?

Received on Friday, 21 February 2003 20:31:27 UTC