tags:

views:

143

answers:

2

In relational databases, the use of primary keys and foreign keys are commonly used to link records across different tables. I'm wondering if I can do the same sort of thing with XML documents. That is, I would like one XML document to contain an element whose value 'points to' the 'primary key' or something similar (maybe the root node?) of a second XML document. The idea is, it would be a reference (kind of similar to a foreign key) to the second document.

My motivation for this is I don't want to store all the content in a single file/document (for many reasons, including data redundancy) but rather in separate files. This link more or less describes what I'm trying to accomplish and suggests some alternatives, but it is restricted to having all the content in a single file (which I don't want to have).

Maybe the hierarchal nature of XML is just too different from a relational database that what I'm trying to do doesn't make sense.

Assuming there is a way to do this, by first preference would be to have a solution that uses XML standards of some variety. Ideally, this would also result in some tooling support (in my case, in an XML editor in Visual Studio would be the ideal case). Failing a standards based solution, if there is a "Microsoft solution" to the problem that would be okay as well. Finally, if no standard or MS solution exists, I would be curious to hear thoughts on a custom solution (or even feedback saying what I'm trying to do just isn't going to work).

Thank you!

A: 

XInclude one document into the other? Last I looked, .NET didn't support XIncudes, but there's an open source XInclude.NET project which adds that support.

Jon Galloway
I think that based on this post, and the other one 'DeadHead' referenced above, the use of XInclude / XPointer seems to be the most standard based solution. Thank you for the mention of the XInclude.NET project. After reviewing http://msdn.microsoft.com/en-us/library/aa302291.aspx, I don't think it's really what I'm looking for. I'm not really interesting in including the content of one XML document in another - I want to establish a reference to something more like a primary key. I know this is not a relation database, but I'm going to have to give this more thought (maybe redesign).
+1  A: 

The traditional solution is to use URLs. If the files all live in the same place, relative URLs will do very nicely. Navigating a link is as simple as opening the URL.

If you want to point to things inside the target document, there are W3C standards - XPointer and XLink - but i don't think they're well supported by tools. You might just write such links as a combination of a URL and an element ID or an XPath expression - you could put the ID or XPath in the fragment identifier of the URL.

Tom Anderson
Thanks, that sounds like a sensible solution. As you mentioned, there isn't any tooling support with basic URLs. And XLink doesn't seem to be adopted by many vendors :(. I haven't looked at XPointer yet.
After more reflection, I'd really like to avoid including another file (or content of another file) and in fact I don't even like the notion of referencing a file name in the URI. What I want to reference is the key value/id of some element. I don't think there's going to be any solution that is standards based (and hence no tooling support) to do this so I'll probably need to come up with a proprietary approach. Thank you for your thoughts and your time!