Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase ««12

SQL 2005: Enter XML Expand / Collapse
Author
Message
Posted Monday, February 19, 2007 5:52 PM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Monday, September 15, 2014 5:20 PM
Points: 1,276, Visits: 1,134

Data stored in relational structures can be represented in many different hierarchies.  It is much more difficult, if not impossible, to do with data stored in hierarchical structures.  Granted, representing complex hierarchies is...well...complex, unless you store it that way.  But in so doing you limit the data's usability for other purposes, and you loose the ability to declare any but the most rudimentary constraints on it.

Hierarchical data stored in relational structures is difficult to maintain and often has artificial limits imposed upon it by software developers because it can be extremely inefficient to retrieve, manipulate, etc.  Not to say that it cannot be done, but not every problem is a nail...  As for constraints, XML Schema provides a very strong typing system, and you can define a wide variety of constraints.  It's not as complex a system of constraints as SQL, but then again it hasn't been around for 3 decades either.  We can probably expect the power of XML to increase over time, as people begin to demand more power.

Hierarchical data management is a mess.  Those who are smart would avoid it.

If you expect XML to be equivalent to, or think that it is a replacement for, relational DBMS then you'll definitely be in for a shock.  I believe you already mentioned that you do have to deal with XML in various forms, and that you currently shred it and put it in the database in relational format.  What's wrong with using SQL Server to do that?

I suppose there is a school of thought that sees the RDBMS as a glorified file cabinet whose only function in life is (or should be) to store relational data.  Then there are those that see more potential in the modern RDBMS as a full-blown application development platform.  Not that there's anything wrong with either view (in my opinion), but I do think it's a little limiting not to consider the full power of your RDBMS platform.

Post #345922
Posted Monday, February 19, 2007 6:26 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Thursday, August 9, 2007 10:18 PM
Points: 6, Visits: 1

Here's a real world situation. I have a web based application that tracks games and points for a poker league. There are certain things that are easiest entered into the backend database using a bulk import.

The poker league is hosted on a provider that does not allow file upload. My current solution uploads player statistics into a MemoryStream object which is converted into an XmlDocument to process into the database. The XML datatype may have been a solution if I needed to keep a copy of the actual uploaded file?

The XML part of the solution is a vast improvement over CSV because of the data typing and heirarchy that the XML allows. 

Season--Location--Game--Players--Player--Points

Without getting too involved in my own solution, the XML hierarchy allows me to put these records into the database in a transaction with rollback and commit features.  I can validate the entire tournament against specific rules. Rules like, you can't have two players in first place. You can only play at one table during a round. So, it takes advantange of the self-describing, self-validating features of XML.

Here's an interesting side effect of this XML file. If I wanted to display the touranment results, I could generate the same XML document and use a style sheet to display it as a web page.  Or, I could store the file as XML in the database...which I am not currently doing.

VARCHAR(8000) is sufficient to handle this situation. The XML datatype could offer an additional schema stamp of authentication to the document. Currently, the benefits don't outweigh the hassle.

Post #345924
Posted Monday, February 19, 2007 7:21 PM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Monday, September 15, 2014 5:20 PM
Points: 1,276, Visits: 1,134

In your situation, where the XML is in a strongly structured, regular format it will probably be advantageous to shred it and store it in relational form.

Without even needing to store the data in an XML column, however, you can still use the SQL Server platform to:

1) validate the XML against an XML Schema,

2) shred the original XML document and store it in your database directly,

3) regenerate the XML from the relational data using the built-in XML functionality (FOR XML PATH clause, for instance),

4) generate the HTML page for you (using FLWOR expressions or the SQLCLR),

5) and accept requests/deliver the HTML page directly to you (via HTTP Endpoints)

One of the chief advantages (IMHO) of the XML data type is that (unlike the old TEXT, NTEXT, and IMAGE LOB data types) you don't have to create columns to hold your XML data in order to take full advantage of its power and flexibility.

Post #345927
« Prev Topic | Next Topic »

Add to briefcase ««12

Permissions Expand / Collapse