How to represent links within XML & XSD?

Discussion in 'XML' started by akunal@gmail.com, May 4, 2006.

  1. Guest

    I'm trying to represent a linked relationship among between nodes as
    follows:

    <!-- Top level nodes -->
    <Cities>
    <City>Los Angeles</City>
    <City>San Francisco</City>
    <City>Seattle</City>
    <City>Washington DC</City>
    </Cities>
    ....
    <Dimensions>
    <Weight>
    <Metric>
    <Tonnes>
    2.5
    </Tonnes>
    </Metric>
    </Weight>
    <Height>
    <Metric>
    <Metres>
    6.4
    </Metres>
    </Metric>
    </Height>
    </Dimensions>
    ....

    <!-- User level nodes -->
    <Address>
    <Line1>...</Line1>
    <Line2>...</Line2>
    <City>/Cities/City[2]</City> <!-- Links to top level nodes -->
    </Address>

    <Truck>
    <Capacity>
    <Weight>/Dimensions/Weight/Metric/Tonnes</Weight> <!-- Links
    to top level nodes -->
    <Height>/Dimensions/Height/Metric/Metres</Height> <!-- Links
    to top level nodes -->
    </Capacity>
    </Truck>


    Is it possible to represent this relationship both at design-time (in
    the schema/XSD) and at run-time (in the XML document)?

    Is there a way to do this in XLink/XPointers such that in Java code I
    could, for example, transparently use the linked objects as follows:

    System.out.println(address.city);
    System.out.println(truck.capacity.weight);
    System.out.println(truck.capacity.height);

    (Unless I absolutely have to, I don't want to write additional code to
    "understand" the semantics of the links to the city, height and weight.
    That is, in a Java program, the links should "automatically" refer to
    and retrieve the top-level data as "objects" rather than just plain
    strings.

    Thanks in advance,
    Kunal
     
    , May 4, 2006
    #1
    1. Advertising

  2. The traditional way to represent point-to-point links within an XML
    document is by an ID attribute defining the point of interest and IDREF
    attributes pointing to those points. Schema does have that concept.

    This does require that you explicitly follow the IDREF connection. The
    standard XML APIs have some assistance for doing so, eg the DOM's
    getElementByID operation. Your example isn't using those APIs -- it's
    assuming data binding -- so you need to check the specs of your data
    binding tool to see what it does in that regard.


    --
    () ASCII Ribbon Campaign | Joe Kesselman
    /\ Stamp out HTML e-mail! | System architexture and kinetic poetry
     
    Joe Kesselman, May 5, 2006
    #2
    1. Advertising

  3. Guest

    The biggest failing of ID/IDREF is that the link has no way of
    expressing any semantic value as to why the relationship was
    established. ID/IDREFs rely on the text that is highlighted to explain
    why the link was inserted. This model works if the authors understand
    the semantic meaning of the links that should point to or from the file
    that they were authoring. And, although this isn't important as yet,
    ID/IDREF can't express bi-directional links.

    I was reading up on XLinks and it appears that XLink enables you to:
    (1) Link between resources without the need to change them (very imp
    req in my case)
    (2) Build new documents dynamically from a template link document
    (could be imp as an alternative)
    (3) Have true bi-directional links between resources (not imp)
    (4) Group sets of related resources in strongly typed relationships
    (imp)
    (5) Link between structured and unstructured information (very imp)
    (6) Manage large repositories of link information in a centralised
    efficient manner (not imp)
    (7) Link resources that are stored in a variety of different data
    repositories (imp)
    (8) Create links using any application that creates XML XLink documents
    (not sure)

    I don't know if ID/IDREF can do those or how XLink can do them, with or
    without using a separate tool other than a traditional XML parser.
     
    , May 5, 2006
    #3
  4. wrote:
    > The biggest failing of ID/IDREF is that the link has no way of
    > expressing any semantic value as to why the relationship was
    > established.


    Not entirely true; that's a matter of how you design your document.
    Remember, the IDREF doesn't exist in a vacuum; its context may provide
    additional information.

    Keys, defined in the Schema spec, are a more flexible alternative to IDs
    and (because there are multiple key spaces rather than a single shared
    space for all IDs) may be more felxible in this regard.

    > ID/IDREF can't express bi-directional links.


    True.

    > I was reading up on XLinks


    XLink is indeed a much richer mechanism. There still isn't much
    off-the-shelf support available for it, unfortunately, so actually using
    it productively can be a challenge. And you did way you didn't want to
    write additional code.


    --
    Joe Kesselman / Beware the fury of a patient man. -- John Dryden
     
    Joseph Kesselman, May 5, 2006
    #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. Markus
    Replies:
    1
    Views:
    1,169
    Markus
    Nov 22, 2005
  2. Replies:
    1
    Views:
    894
    Martin Honnen
    Jan 14, 2004
  3. Matt
    Replies:
    3
    Views:
    37,307
    MKNDK
    Sep 11, 2008
  4. stiank81
    Replies:
    4
    Views:
    15,496
    stiank81
    Jun 26, 2005
  5. Rushi
    Replies:
    1
    Views:
    576
Loading...

Share This Page