Gerry Laenen wrote:
Quote:
I am currently working on creating an XSD schema. I have
an element defined that should be self-refering
(child-parent principle). Here is a sample:
|
I'm not sure it's a good idea. XML is ill-suited for
storing relational data, XML is meant for storing tree-like
data. And here you are, storing tree-like data in XML using
workarounds meant for storing tree-like data in RDBMS. Why?
Quote:
<GWLC>
<GROUPS>
<GROUP>
<NAME>ParentGroup</NAME>
<PARENT></PARENT>
</GROUP>
<GROUP>
<NAME>ChildGroup1</NAME>
<PARENT>ParentGroup</PARENT>
</GROUP>
</GROUPS>
</GWLC>
|
Why not:
<GWLC>
<GROUPS>
<GROUP NAME="ParentGroup">
<GROUP NAME="ChildGroup1"/>
</GROUP>
</GROUPS>
</GWLC>
Quote:
The schema a currently have is valid, but it does not
validate the existance of a parent group (foreignkey
constraint). Secondly, I want each name to be uniqe. The
applicable section off the schema:
|
*sigh* It would've been a better idea to post a working
schema instead of some disjecta membra. But I guess I
should give up on my 'help me help YOU' rants. They don't
seem to work anyway.
<xs:element name="GROUPS" id="GROUPS">
<xs:complexType>
<xs:sequence>
<xs:element ref="GROUP" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<xs:unique name="UC_Group">
<xs:selector xpath="./GROUP"/>
<xs:field xpath="NAME"/>
</xs:unique>
<xs:keyref name="FK_GROUP_GROUP" refer="UC_Group">
<xs:selector xpath="./GROUP"/>
<xs:field xpath="PARENT"/>
</xs:keyref>
</xs:element>
<xs:element name="GROUP" id="GROUP">
<xs:complexType>
<xs:sequence>
<xs:element name="NAME" type="xs:string"/>
<xs:element name="PARENT" minOccurs="0"
type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
Note that it allows loops, self-references and whatever
else. All thanks to the fact you're storing your data in
an unnatural way.
--
Pavel Lepin