Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Detecting Circular references in XML Schema Definition (XSD) types.

843834Apr 21 2009 — edited Apr 21 2009
Hi guys,

I have build a XSDParser in java using the org.eclipse.xsd package, now we need to detect circular references in between different types and elements.

PS: bf is the target namespace prefix.

The cases are such that a type shouldn't refer to itself.
	<xs:complexType name="Test">
		<xs:sequence>
			<xs:element name="Name1" type="bf:Test" />
			<xs:element name="Name2" type="xs:string" />
			<xs:element name="Name3" type="bf:Test" />
		</xs:sequence>
	</xs:complexType>
An element shouldn't refer itself
	<xs:element name="Test">
		<xs:complexType>
			<xs:sequence>
				<xs:element ref="bf:Test" />
			</xs:sequence>
		</xs:complexType>
	</xs:element>
An element is having an element inside a complex anonymous which uses a complex type as its type. Then that complex type should not refer to this element
	<xs:element name="Test1">
		<xs:complexType>
			<xs:sequence>
				<xs:element name="Name1" type="bf:T1" />
				<xs:element name="Name2" type="xs:string" />
			</xs:sequence>
		</xs:complexType>
	</xs:element>

	<xs:complexType name="T1">
		<xs:sequence>
			<xs:element name="xyz">
				<xs:complexType>
					<xs:sequence>
						<xs:element ref="bf:Test1" />
					</xs:sequence>

				</xs:complexType>
			</xs:element>
		</xs:sequence>
	</xs:complexType>
And last but not the least a circular reference like this should also be detected
	<xs:complexType name="Test">
		<xs:sequence>
			<xs:element name="Name2" type="xs:string" />
			<xs:element name="Name3" type="bf:Test1" />
		</xs:sequence>
	</xs:complexType>

	<xs:complexType name="Test1">
		<xs:sequence>
			<xs:element name="Name1" type="bf:Test2" />
			<xs:element name="Name2" type="xs:string" />
		</xs:sequence>
	</xs:complexType>

	<xs:complexType name="Test2">
		<xs:sequence>
			<xs:element name="Name1" type="bf:Test" />
			<xs:element name="Name2" type="xs:string" />
		</xs:sequence>
	</xs:complexType>
What I would like to know is that is there any inbuilt feature that provides the facility of detecting such legal circular references, if not then how do I go about achieving this in JAVA a little help would be appreciated.

Thanks
jSlogger
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 19 2009
Added on Apr 21 2009
1 comment
766 views