Search code examples
sqlxsltgraph-databasessqlxml

Transform / query SQL database to XML document?


I have a very basic database with tables for nodes, node-properties and node-relationships. The relationships are just pointers with no particular implied graph structure.

Now I want to query this database to build an xml document with a hierarchical structure based on certain relationships in this database.

Let's say I have nodes A, B and C where C is related to B as parent, B->A:parent, C->A:user, A->B:context.

The database doesn't know anything about any hierarchies but now I want to build a hierarchical XML document based on the relationships named "parent".

On top of that I will also want to add the node properties and other relationships to this graph, as well as transient properties such as the number of nodes directly related to other nodes as for instance "owner" etc.

So my question is: Is this anything you'd commonly do? Can it be done with any existing tools in the Microsoft or 3:rd party world or do I have to build this xml structure manually step by step?

What I ideally want is something similar to how XSLT/XPath works where you navigate the source (sql-db in this case) and transform it into another structure.

I guess it's somehting similar to a pivot table (but not a table but a hierarichal graph).


Solution

  • I think I found my answer now. "FOR XML" seem to be my friend.