Yet another XSD question

G

Gerry Laenen

Hi all,

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:

<GWLC>
<GROUPS>
<GROUP>
<NAME>ParentGroup</NAME>
<PARENT></PARENT>
</GROUP>
<GROUP>
<NAME>ChildGroup1</NAME>
<PARENT>ParentGroup</PARENT>
</GROUP>
</GROUPS>
</GWLC>

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:

<!-- ************************************ -->
<!-- * Description of the GROUPS element* -->
<!-- ************************************ -->
<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:selector>
<xs:field xpath="NAME"></xs:field>
</xs:unique>
</xs:element>

<!-- *********************************** -->
<!-- * Description of the GROUP element* -->
<!-- *********************************** -->
<xs:element name="GROUP" id="GROUP">
<xs:complexType>
<xs:sequence>
<xs:element name="NAME"/>
<xs:element name="PARENT"/>
</xs:sequence>
</xs:complexType>
<xs:key name="PK_GROUP">
<xs:selector xpath=".//GROUP"/>
<xs:field xpath="NAME"/>
</xs:key>
<xs:keyref name="FK_GROUP_GROUP" refer="PK_GROUP">
<xs:selector xpath=".//GROUP"/>
<xs:field xpath="PARENT"/>
</xs:keyref>
</xs:element>


Thanks for helping!

Gerry
 
P

p.lepin

Gerry said:
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?
<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>
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top