Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Typed recursive element

Status
Not open for further replies.

jammusi2

Programmer
Joined
Mar 10, 2010
Messages
3
Location
IL
Hi,
1. Need to define XSD element that has some attributes and can hold list of itself

This is the type definition:

<xs:complexType name="t_TestCase" >
<xs:sequence>
<xs:element type="t_TestCase" minOccurs="0"></xs:element>
</xs:sequence>
</xs:complexType>

This is the element based on the type:
<xs:element name="TestCase" type="t_TestCase"></xs:element>

3. BUT - when adding attribute to the type - it seems that it is not valid anymore. (the sequence tag is invalid)

<xs:complexType name="t_TestCase" >
<xs:attribute name="att1"></xs:attribute>
<xs:sequence>
<xs:element type="t_TestCase" minOccurs="0"></xs:element>
</xs:sequence>
</xs:complexType>

Advise please?

Tx

Oren
 
[1] In the case of element free of attribute, you should script both the name (x, say) and type; otherwise, it can't be correct. Alternative, you may have a global element defined, and the child xs:element of xs:sequence references it. Take the first structure as an example.
[tt]
<xs:complexType name="t_TestCase" >
<xs:sequence>
<xs:element [red]name="x"[/red] type="t_TestCase" minOccurs="0"></xs:element>
</xs:sequence>
</xs:complexType>
[/tt]
[2] In the case of element of the type with attribute, you have to position the xs:attribute> after the xs:sequence element, otherwise, the schema document is incorrect. Now, take the second structure as mentioned in [1] using reference say.
[tt]
<xs:complexType name="t_TestCase" >
<xs:sequence>
<xs:element [red]ref="x"[/red] type="t_TestCase" minOccurs="0"></xs:element>
</xs:sequence>
[red]<xs:attribute name="att1"[blue] type="xs:string"[/blue]></xs:attribute>[/red]
</xs:complexType>

[blue]<xs:element name="x" type="t_TestCase" />[/blue]
[/tt]
 
Thanks
I am using Visual Studio and when doing as suggested there is a warning message regarding the nested defined element as follows:

If ref is present, all of <complexType>, <simpleType>, <key>, <keyref>, <unique>, nillable, default, fixed, form, block, and type must be absent.


Why is that?

<xs:element name="TestCase" type="t_TestCase"></xs:element>

<xs:complexType name="t_TestCase" >
<xs:sequence>
<xs:element ref="TestCase" type="t_TestCase" minOccurs="0" />
</xs:sequence>
<xs:attribute name="att1" type="xs:string"></xs:attribute>
</xs:complexType>
 
[2.1] Sorry, I should have deleted type attribute in the case of using ref attribute, sure. The corresponding line should be read like this.
[tt] <xs:element ref="x[highlight]" m[/highlight]inOccurs="0"></xs:element>[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top