key and keyref

Discussion in 'XML' started by Mike, Sep 23, 2005.

  1. Mike

    Mike Guest

    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.
    Mike, Sep 23, 2005
    #1
    1. Advertising

  2. 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.
    >
    Steve Jorgensen, Sep 24, 2005
    #2
    1. Advertising

  3. Mike

    Mike Guest

    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.
    >>

    >
    Mike, Sep 26, 2005
    #3
  4. Mike

    JAPISoft Guest

    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.
    >
    >
    JAPISoft, Sep 27, 2005
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. J E E
    Replies:
    0
    Views:
    377
    J E E
    Nov 7, 2003
  2. peterpeter
    Replies:
    0
    Views:
    927
    peterpeter
    Feb 11, 2004
  3. John Carron
    Replies:
    0
    Views:
    471
    John Carron
    Sep 1, 2005
  4. peterpeter
    Replies:
    0
    Views:
    734
    peterpeter
    Feb 12, 2007
  5. boeledi

    XSD: key and keyref problem

    boeledi, Oct 15, 2007, in forum: XML
    Replies:
    4
    Views:
    1,138
    Kris824
    Sep 6, 2012
Loading...

Share This Page