Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > key and keyref

Reply
Thread Tools

key and keyref

 
 
Mike
Guest
Posts: n/a
 
      09-23-2005
In my XML document, I am defining a key on an element, which works fine. I
also have the corresponding keyref element in place to enforce ref.
integrity.

The issue: it's not necessary that an entity have a parent. But, if a parent
ID is specified I want to validate that against the key. For example:

<Objects>
<Object>
<ID>1</ID>
<ParentID/>
</Object>
<Object>
<ID>2</ID>
<ParentID>1</ParentID>
</Object>
</Objects>

In this example, object ID "2" is a child of "1". Since "1" is the parent,
I don't need to validate ParentID (i.e. when it doesn't have a value, don't
validate with keyref).

Any ways around this?

Thanks.


 
Reply With Quote
 
 
 
 
Steve Jorgensen
Guest
Posts: n/a
 
      09-24-2005
I would make the ParentID element optional rather than making its value
optional. If you do that, you're problem is automatically solved because if
and only if the element exists, its value must match a key.

On Fri, 23 Sep 2005 18:04:56 -0400, "Mike" <> wrote:

>In my XML document, I am defining a key on an element, which works fine. I
>also have the corresponding keyref element in place to enforce ref.
>integrity.
>
>The issue: it's not necessary that an entity have a parent. But, if a parent
>ID is specified I want to validate that against the key. For example:
>
><Objects>
> <Object>
> <ID>1</ID>
> <ParentID/>
> </Object>
> <Object>
> <ID>2</ID>
> <ParentID>1</ParentID>
> </Object>
></Objects>
>
>In this example, object ID "2" is a child of "1". Since "1" is the parent,
>I don't need to validate ParentID (i.e. when it doesn't have a value, don't
>validate with keyref).
>
>Any ways around this?
>
>Thanks.
>


 
Reply With Quote
 
 
 
 
Mike
Guest
Posts: n/a
 
      09-26-2005
Thanks, Steve!

"Steve Jorgensen" <> wrote in message
news:...
>I would make the ParentID element optional rather than making its value
> optional. If you do that, you're problem is automatically solved because
> if
> and only if the element exists, its value must match a key.
>
> On Fri, 23 Sep 2005 18:04:56 -0400, "Mike" <> wrote:
>
>>In my XML document, I am defining a key on an element, which works fine. I
>>also have the corresponding keyref element in place to enforce ref.
>>integrity.
>>
>>The issue: it's not necessary that an entity have a parent. But, if a
>>parent
>>ID is specified I want to validate that against the key. For example:
>>
>><Objects>
>> <Object>
>> <ID>1</ID>
>> <ParentID/>
>> </Object>
>> <Object>
>> <ID>2</ID>
>> <ParentID>1</ParentID>
>> </Object>
>></Objects>
>>
>>In this example, object ID "2" is a child of "1". Since "1" is the
>>parent,
>>I don't need to validate ParentID (i.e. when it doesn't have a value,
>>don't
>>validate with keyref).
>>
>>Any ways around this?
>>
>>Thanks.
>>

>



 
Reply With Quote
 
JAPISoft
Guest
Posts: n/a
 
      09-27-2005
Hi Mike,

May be you coud specify that the first object has no parent content with
the nil attribute.

<Objects xmlnssi="http://www.w3.org/...">
<Object>
<ID>1</ID>
<ParentID xsi:nil="true"/>
</Object>
...
</Objects>

When you use a nil attribute it will notify to the parser to ignore this
node content and thus you can have only one definition inside your W3C
Schema (simplifying key and keyref usage).

Best wishes,

A.Brillant
EditiX - XML Editor and XSLT Debugger


Mike wrote:
> In my XML document, I am defining a key on an element, which works fine. I
> also have the corresponding keyref element in place to enforce ref.
> integrity.
>
> The issue: it's not necessary that an entity have a parent. But, if a parent
> ID is specified I want to validate that against the key. For example:
>
> <Objects>
> <Object>
> <ID>1</ID>
> <ParentID/>
> </Object>
> <Object>
> <ID>2</ID>
> <ParentID>1</ParentID>
> </Object>
> </Objects>
>
> In this example, object ID "2" is a child of "1". Since "1" is the parent,
> I don't need to validate ParentID (i.e. when it doesn't have a value, don't
> validate with keyref).
>
> Any ways around this?
>
> Thanks.
>
>

 
Reply With Quote
 
 
 
Reply

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 On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
XSD: key and keyref problem boeledi XML 4 09-06-2012 06:47 AM
problems with key/keyref and complex-type inheritance peterpeter XML 0 02-12-2007 08:17 PM
Xml Schema substitution groups / key and keyref John Carron XML 0 09-01-2005 06:52 PM
XML schema - key/keyref and inheritance peterpeter XML 0 02-11-2004 01:38 PM
Can't use key and keyref with an attribute in a group J E E XML 0 11-07-2003 12:42 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57