SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


SQL 2005: Enter XML


SQL 2005: Enter XML

Author
Message
Mike C
Mike C
SSCrazy
SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)

Group: General Forum Members
Points: 2799 Visits: 1168

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.


Frank Thompson-290923
Frank Thompson-290923
Grasshopper
Grasshopper (18 reputation)Grasshopper (18 reputation)Grasshopper (18 reputation)Grasshopper (18 reputation)Grasshopper (18 reputation)Grasshopper (18 reputation)Grasshopper (18 reputation)Grasshopper (18 reputation)

Group: General Forum Members
Points: 18 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.


Mike C
Mike C
SSCrazy
SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)

Group: General Forum Members
Points: 2799 Visits: 1168

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.


Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search