Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old December 20th, 2006, 10:45 AM
Gerry Laenen
Guest
 
Posts: n/a
Default Yet another XSD question

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


  #2  
Old December 20th, 2006, 12:45 PM
p.lepin@ctncorp.com
Guest
 
Posts: n/a
Default Re: Yet another XSD question


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

 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles