tags:

views:

24

answers:

1

Hi all,

I'm sure this is a very basic XML question, but I can't find the answer anywhere. What is the most commonplace way of referring to a particular XML node at multiple other places inside the same XML document?

For example, consider a document like

<?xml version="1.0" encoding="ISO-8859-1"?>
<library>
  <author id="john">
    <name>John Brown</name>
  </author>
  <book>
    <title>How To Peel Bananas In 10 Simple Steps</title>
    <author ref="#john"/>
  </book>
  <book>
    <title>Why Bananas Grow Upward</title>
    <subtitle>How The Main World Religions View Banana Growth</subtitle>
    <author ref="#john"/>
  </book>
</library>

Clearly, the author node inside book nodes is intended to be a reference to the top-level author node. Ideally, when loading such a document into some OO programming language, the author attribute of a Book object would directly refer to the same Author object as the one that was created earlier on.

Clearly, my way of writing this down in XML is nonstandard and requires extra work after loading. Nevertheless, I'm sure people are storing cross-referenced stuff in XML all the time. What is the best and/or easiest and/or most "correct" feature to do something like this? What way is best supported by supporting standards, such as XPath and the likes?

I read about XLink but I'm not sure if it's the best solution - it also seems rather outdated and unused (is that true)?

A: 

The XML posted is valid. Nothing wrong with multiple references to the same element.

Is your question about hydrating an object model from this XML?

Oded
Well, I'm not asking about what is valid, I'm asking about what is best practice. You write that there is "nothing wrong with multiple references to the same element". Does that mean that there is a standard way to refer to elements, then? Did I hit it by chance?My question is *also* about hydrating an object model; it is about the preferred XML layout for something that has references inside it, such that hydrating objects is also easy.
skrebbel