473,395 Members | 1,452 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

key and keyref

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.
Sep 23 '05 #1
3 1279
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" <no****@comcast.net> 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.


Sep 24 '05 #2
Thanks, Steve!

"Steve Jorgensen" <no****@nospam.nospam> wrote in message
news:ls********************************@4ax.com...
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" <no****@comcast.net> 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.

Sep 26 '05 #3
Hi Mike,

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

<Objects xmlns:xsi="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.

Sep 27 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: peterpeter | last post by:
Hi. There is a XML schema problem that I have with key/keyref: I have two complex (A and B) types which both inherit from a common base typ (Base). A refers B using a xs:IDREF element named...
0
by: Markus Seibold | last post by:
Hello NG, sorry for pasting that much code but I just can't figure out how get the <key><keyref> to work in XML Schema. I am using XMLSpy 4.3 for editing my XML. I want to represent a...
5
by: Russell O'Connor | last post by:
The following XML and Schema doesn't validate in Visual Studio .NET 2003. Is there some mistake I'm making, or is VS.NET in error. The error is r:\test2.xml(3): The key sequence 'foo' in Keyref...
0
by: mark.van.der.voort | last post by:
Hi, I have defined a simple key/keyref validation for describing a tree. <xs:key name="key_member"> <xs:selector xpath=".//member"/> <xs:field xpath="@id"/> </xs:key> <xs:keyref...
0
by: jacksuyu | last post by:
I have two xsd files, in one xsd file, I defined a "key", I'd like to use "keyref" to refer to that "key" from another xsd file. But I always get attribute is empty error. my.xsd is my first xsd...
1
by: Dmitry Martynov | last post by:
Hi I have a question whether XmlValidatingReader doesn't check keyref constrain (the same with key constraint) or I do smth wrong. I have the following schema <?xml version="1.0"...
0
by: Kent Boogaart | last post by:
Hi, Suppose an XSD as follows: <xsd:complexType name="myType"> <xsd:complexContent> <xsd:extension base="myBaseType"> <xsd:sequence> <xsd:element name="thing" minOccurs="0"...
2
by: svestin | last post by:
Hi All! I run into a problem defining a XSD schema with KEYREF references. Is it possible to use KEYREF with nillable fields? Just like a database where a FK could be null. In the example...
4
by: jasonnerothin | last post by:
I'm trying to figure out exactly what's going wrong with an xpath keyref validation scenario. In brief, I have something like the following in my xsd: <xs:schema> <xs:complexType...
0
by: peterpeter | last post by:
Hi. There is a XML schema problem that I have with key/keyref: I have a complex type "AExtended" which inherits from a base type "ABase". Both are allowed to be instantiated under the "Root"...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.