Brett Kaiser (x002548) Blog

Not Just a Number - Brett Kaiser

The Official XML Ranting Site

XML RANT

EDIT:  1/12/2005 Hey Look!  An Official  He-Man  XML Haters Club Thread

 http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=44577

Until someone can post some reason why XML in SQL Server is a good thing, I'm starting this Official XML Ranting Post.

I will start a list of why I dislike XML in SQL Server.  My Ignorance is unbounded.

"Let's take the nice relational model and add to it hierarchical "capabilities" But let's make sure the data is stored in a text column, so they can get it out in chuncks, so they can the use these "tools" to parse it out into relational format, where it can be stored, and more easily accessed....

Did I mention I hate XML“


 

1.  Because a Rant was requested

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=39339

2.  Because My Ignorance is showing...how do you get xml out of sql server?  Was having a conversation here ...interesting database...tried all the version of code snipets....no joy, expect to the QA result pane...what a PAIN

http://www.dbforums.com/showthread.php?p=3771308&posted=1#post3771308

USE Northwind
GO

CREATE VIEW myView99
AS
SELECT 1                    as Tag,
         NULL                 as Parent,
         Customers.CustomerID as [Customer!1!CustomerID],
         NULL                 as [Order!2!OrderID]
FROM Customers
UNION ALL
SELECT 2,
         1,
         Customers.CustomerID,
         Orders.OrderID
FROM Customers, Orders
WHERE Customers.CustomerID = Orders.CustomerID
ORDER BY [Customer!1!CustomerID], [Order!2!OrderID]
FOR XML EXPLICIT
GO

CREATE TABLE myTable99(Col1 varchar(8000))
GO

INSERT INTO myTable99(Col1)
SELECT * FROM (
SELECT 1                    as Tag,
         NULL                 as Parent,
         Customers.CustomerID as [Customer!1!CustomerID],
         NULL                 as [Order!2!OrderID]
FROM Customers
UNION ALL
SELECT 2,
         1,
         Customers.CustomerID,
         Orders.OrderID
FROM Customers, Orders
WHERE Customers.CustomerID = Orders.CustomerID
ORDER BY [Customer!1!CustomerID], [Order!2!OrderID]
FOR XML EXPLICIT) AS XXX
GO

CREATE PROC mySproc99
AS
SELECT 1                    as Tag,
         NULL                 as Parent,
         Customers.CustomerID as [Customer!1!CustomerID],
         NULL                 as [Order!2!OrderID]
FROM Customers
UNION ALL
SELECT 2,
         1,
         Customers.CustomerID,
         Orders.OrderID
FROM Customers, Orders
WHERE Customers.CustomerID = Orders.CustomerID
ORDER BY [Customer!1!CustomerID], [Order!2!OrderID]
FOR XML EXPLICIT
GO

EXEC mySproc99

INSERT INTO myTable99 EXEC mySproc99
GO

DROP TABLE myTable99
DROP PROC mySproc99
GO

 

3. Because of this

http://weblogs.sqlteam.com/mladenp/archive/2009/12/01/SQL-Server-Network-packet-size-difference-between-returning-XML-and.aspx

 


 

Legacy Comments


Davide Mauri
2004-09-02
re: The Official XML Ranting Site
Seems that ALL database purists hate XML. I LOVE it as much as i love sql. But this doesn't mean that i'll take all my columns, put it into an XML document and store it in an text o xml column.
Good or bad just pedends from who uses it. Anything can be misused....as the post here shows http://thedailywtf.com/archive/2004/09/01/1511.aspx, and XML is not evil by default :-)

Of course what can happen is that who knows only xml will put xml everywhere even where not welcome, but who is in fault? That man or XML support?

Btw i'll post you a problem that i've solved using XML, where i cannot image an efficent why to solve with SQL and relations only :-)

PS
I just what to evidence that i really LOVE SQL, and i spend on it 80% of my time. But i another thing offer me something interesting, why not take the best of them, so that my work can be even more efficent?

Brett
2004-09-02
Uses for XML...besides publishing?
I'd love to see the problem that could only be solved with XML. Does it have anything to do with data access?


sitka
2004-09-02
re: The Official XML Ranting Site
Thanks Brett for creating this post, I don't have enough experience with XML to make good arguments yet because so far everytime I get an opportunity to dig into it I get dragged away to use another set of watered down skills. So far I know it hurts my brain when I tried to build schema(s)?

Brett
2004-09-02
Thanks Sitka
But thta's the problem...people seem to force a solution just to use xml...

Only to my consternation...


Jay
2004-09-02
re: The Official XML Ranting Site
As with any design, there are definitely some tradeoffs. XML as a transport is clearly not the most performant mechanism for database access. There is a lot of markup that is being transported over the wire. But as shown, by using XML as the transport to and from the database and OpenXML as the persistence mechanism, one can significantly decouple the database layer from the business logic layer and thereby develop a very flexible and extensible design. In general, it comes down to the particular requirements of a given application.

Davide Mauri
2004-09-02
re: The Official XML Ranting Site
And sometimes happen that people seem to force a solution justo to use SQL :-)

Brett, i'm not saying that XML can replace SQL, i'm saying that, using them togheter in a *correct* way you can improve the efficienty of your solution.

By efficenty i wide the meaning not only to performance but also to development times, easy of manutenution and / or changes, and so on.

This weekend i'll post a detailed case in which i *still* think that XML is good when used with SQL.

In the meaning, i'll say that i found FOR XML clause really good, since it is possible to create a web page just passing the result of a query right out into an XSLT an then - voilà - you get your page (or flash menu, or SVG file....)

Do you think that FOR XML is bad? Or your hate is limited only to the OPENXML function and the XML datatype (and all its nice functions?)

Last point. I'm using SQL 2005 BETA 2 and performaces of XML queries SUCKS, so i'm not going to really use xml datatype a lot until performances are decent. But i like the idea behind, though it should be used only in rare cases and with a LOT of attention.

Brett
2004-09-02
re: The Official XML Ranting Site
No. Creating web pages from sql "on the fly" is kinda cool.

I thought sp_makewebtask was fabulous when I first laid my eyes on 7.

To Jay's point though, I have never seen, nor do I seem to have the ability grasp, how the database layer can be separated from the business logic layer.

I mean, as a general rule, I always isolate the business logic layer IN the database.

So what are the magic bullet steps that allow the business logic to isolated from the database?

It smacks of highly dynamic stuff...no?


Travis Laborde
2004-09-02
re: The Official XML Ranting Site
I'll never be the guy to store my data in one big text column as XML, but I do think that XML support in SQL Server is a good thing. Two uses that I have for it are:

1) It is a VERY nice way to send in multiple rows of data for insert/update/whatever all at once. Have a sproc that takes a big varchar parameter which is a properly formatted XML document, and you can use it just as you could any table.

2) It works well with Data Islands in web development.

But again, these are ways of getting data INTO and OUT OF the relational tables in SQL Server. That's as far as it goes :)

Brett
2004-09-02
Properly formatted XML
I wonder what that really means?

Also do you need to know the tags before hand?

Perhaps not, if you write some code yourself.

But you Do have to with the SQL commands (Are they really sql commands?)

I mean the deciphering part could get messy with all of the possible recursion...

When you say
>> It is a VERY nice way to send in multiple rows of data for insert/update/whatever all at once. Have a sproc that takes a big varchar parameter which is a properly formatted XML document, and you can use it just as you could any table.

What does that mean and how do you do that?


Davide Mauri
2004-09-02
RE: The Official XML Ranting Site
Wow! Thaks to Travis i'm not alone in the lion's den :-)

Btw, Travis first's point show one thing that without XML wouln'd have possibile: pass an arbitrary number of parameters to a stored procedure.

Davide Mauri
2004-09-02
RE: The Official XML Ranting Site
I also isolate business login on the data tier too, but only if it operates directly ("near") the data. In this case SP rules.

But business logic that does not operate directly on the data is better implemented in a class using .NET or some OO language.

Now, just to make an example, let's say we have the classic Order - Order Detail case.

Let's say Order is a computer order, and Order Details are all the pieces that compose a computer.

You can have 2 business logic tiers:
First Tier: Check that all components are compatible. Eg. AMD CPU with the right motherboad
Second Tier: Check that all components are available.

I'll implement the first tier in a .NET Class, and the second with as Stored Procedure.
I'd like to avoid having "begin tran" and "commit tran" in the first tier. I preferer to do such things i the second one, which is nearer to the data.
Well, without XML this will be impossible.
With XML you can pass to the SP a document that contains everything in need to make order (so Order + Order Details data), and inside, with OPENXML, use XML as a table, using the standard SQL DML commands, putting everything inside a transaction.

If interested i'll post a sample.

Brett
2004-09-02
Interested? You bet
Sure, but if you code your first rule in .net, doesn't that make it static?

What happens when you get new "options" for the computer?

Don't you have to open up the code?

And as fars as a "documnet" couldn't you just pass the values as parameters in 1 row to a sproc?

Is it the fact that the parameter order is important here? Does that cause a lot of pain in the front end?




sitka
2004-09-02
re: The Official XML Ranting Site
Please don't be harsh, but the graciousiousness of our host demands I humble myself.
An XML document can carry with it the data design rules it needs along with it in markup and/or an acompanning schema definition this allows an enduring package for say xcopy style editing or power down persistence. Data with metadata so to speak. Then hook backup after a certain amount of time and propogate changes to the live database store. If that is the type of functionality XML brings to the table isn't it about ten years too late. Gosh, how long is anyone unplugged these days. And the data has less value as it is in a MORE NON-concurrent state because pending changes are sitting around out there resident in an XML world.

DavidM
2004-09-02
re: The Official XML Ranting Site
Good database people SHOULD hate it. Codd, Date et al.. have spent the last 30+ years showing why RM is as good and indeed better at representing and querying schema's. This history is completely ignored or unknown to a lot of people in IT.

The last gig I was at, the client received everything via web services. The applications domains would arrive at startup in a 2MB gzipped XML stream.

When I arrived on the seen, querying this delightful bundle was some of the most complicated and confusing code I have seen in a while. I spent the next couple of days building the DataTable relational operators (the ones on my blog) and the next week converting and debugging the old stuff.

XML definately has its uses, but should not be relied on as a data management tool.

sitka
2004-09-02
re: The Official XML Ranting Site
This might be a lightbulb moment.....

David Mauri says
"First Tier: Check that all components are compatible. Eg. AMD CPU with the right motherboad"

Brett replies
"What happens when you get new "options" for the computer?"

This is what I see to, or don't understand yet. The solution here seems to be haul down a whole lot more data than you need and get it resident in the first teir.
What about the discipline of
"get in, get what you need quickly,
and slam the door on your way out."
You are more conncurrent then, that closeness to concurrency is a cherished thing in my book.
Perhaps I'm missing the scale of billions of connections negotiated but wouldn't one rather rely on the pace of networks, server hardware and data provider library development to keep pace with increasing needs. Thus striving to represent truer concurrency as opposed to a gluttonous hunger for recreating what already exists just so you can fleetingly POSSESS it.

Brett
2004-09-03
Huh?
>>Perhaps I'm missing the scale of billions of connections negotiated but wouldn't one rather rely on the pace of networks, server hardware and data provider library development to keep pace with increasing needs. Thus striving to represent truer concurrency as opposed to a gluttonous hunger for recreating what already exists just so you can fleetingly POSSESS it.<<

Speak slowly...I have a hangover.....

And...what book?


Jay
2004-09-03
re: The Official XML Ranting Site
>> XML definately has its uses, but should not be relied on as a data management tool

David, how do you define "data management tool" ?
Do you consider content to be data, as in a content management system?


sitka
2004-09-03
re: The Official XML Ranting Site
"Musing About Which One Knows Not"
sitka's fourth book of the "Fair Warnings"
trilogy


Brett
2004-09-03
XML Has it's uses
Seems like that's what people say...

I've just never seen one, or had somebody explain it


Hassan Voyeau
2004-09-03
re: The Official XML Ranting Site
"Btw, Travis first's point show one thing that without XML wouln'd have possibile: pass an arbitrary number of parameters to a stored procedure."

I disagree, an arbitrary amount of paramters can be passed using a comma separated string...you do not HAVE TO USE XML.

rockmoose
2004-09-03
XML is good for ?
1. Data storage ? - No.
Relational systems are more suited for this task.

2. Data interchange ? - No.
In data interchange scenarios you need a)the interchange format(metadata) b)the data.
XML solves the data interchange issue in an highly inefficient and redundant way.

3. Document markup ? - Yes.
This was it's primary purpose was it not.

Now,
A lot of work has gone into the XML "technology" to solve 1 & 2, and the soup is getting thicker by the day... xpath, xquery, xslt , xthis, xthat, xblahblah..
This is the result for trying to solve specific problems with the wrong tool, suboptimal technology.

Well, with enough ducttape and glue you can probably build bridges with toothpicks.

Davide Mauri
2004-09-04
re: The Official XML Ranting Site
Hassan, passing a comma-delimited list will force you to split it up and do a lot of unuseful work, since you'll be doing what XML excatly already does.

Now, let's go with a challenge of the next post...

Davide Mauri
2004-09-04
Sample use of XML & SQL.
Introduction:
I'm a developer, and i use every day SQL, XML and C#. I try to find solution that take the best of this 3 worlds and allow me to create the best solution i can with the budget assigned.

Example:
The need is to build an e-commerce site. First thing to do is to create a shopping basket. The best solution today, for me, is:
- Show the catalog to the user using pure SQL commands (no XML here)
- When the user put it's first item in his basket, create and XML that can store the basket (Using .NET i'll use a DataSet or DataTable or a Custom Class).
- If the user what to save the basket for future use, just serialize it into XML and save it into the database in a text or xml column
- If the user what to commit its basket, serialize it into XML and pass this to a SP that with OPENXML (so the original XML is decomposed) will make the order in a sigle transaction, completely on the DB.
- If the user that to se its order history, take its orders, query them with FOR XML, give it to XSLT and create the HTML page

Request:
Someone of the XML haters here can give me a solution that is better then what i described above.
With better I mean:
- More Efficent
- More Easy
- Less Expensive \ Time Consuming
- That better divide the load among web server and sql server

Note:
I think that in the solution I described none of the techonogies used use misused. This is the way i mean that XML is not bad at all.
Having the possibility to choose between SQL, XML and the CLR is up to us to choose the best solution for the problem with have to solve.
I think that the possibility to choose is always better that being forced to use SQL o XML beacuse there are no other tecnologies available.

After all the possibility to choose IS freedom and freedom IS responsability. So now, with so many tecnhologies available is our responsability to choose the best for us. Without preconception.

Before the end just a notice. I posted this sample and this opinion not to be polemic, but just to know opinions from you all.

Good Luck!

sitka
2004-09-04
re: The Official XML Ranting Site
Thanks Davide Mauri for the example.

Hassan Voyeau
2004-09-04
re: The Official XML Ranting Site
That was never my argument, I was arguing against the point made that it would have been NOT POSSIBLE to do without xml.

Hassan Voyeau
2004-09-04
re: The Official XML Ranting Site
-- More efficient than writing to a table? how come?

-- More easy than using a stored proc to retrieve the items in a basket? how come?

-- Less expensive / time consuming than a simple sql query and a custom class to generically format your query results into html. How come?

-- better diving the load? How come.

rockmoose
2004-09-04
re: The Official XML Ranting Site
You take an oxcart, paint it red, add some spoilers, fenders, chrome wheels and a bunch of other nifty accessories. You tell everyone it's a XFerrari and hype it to the max.
Everyone will think it's a really efficient and great new thingy, it has to be a really good thing. With Xform you can turn it into any kind of oxcart you want: red, white, blue, banana flavor, chocolat mint. It even does hierarchies, so you can put one oxcart into another, just pile them up.

Now ain't that great!
Not to mention it's really efficient, since it's an XFerrrari !

This is a rant right ;-)

rockmoose
2004-09-05
re: Sample use of SQL & XML request
Without thinking too hard...

- Show the catalog to the user using pure SQL commands
- When the user put it's first item in his basket, create an item instance and add it to the basket class itemcollection (Using .NET i'll use a Custom Class ).
- If the user what to save the basket for future use, just save the basket and items in the database.
Or serialize the object into binary and save in binary column.
- If the user whant to commit its basket, update the basket to commit status in the db
- If the user want to see its order history, query the database, format and create the HTML page

There really is no point in using XML anywhere.
If you don't want to use custom classes you can use .NET DataSet ov course. The fact that a DataSet is in XML is M$ design and really relevant to this discussion. The XML probably just makes the ds slower.

/rockmoose

Brett
2004-09-07
Yes this is a rant
lol...but what's a rockmoose....

And doesn't .net have arrays?

And how would you build an XML "document" to store the values selected during a "session".

Wouldn't that be sysnonamoose to building an array?


Brett
2004-09-09
Ok..Ok...Don't let the bad puns stop ya
oye...sysnonamoose...

but seriously..if I define my array to mean something, and you use tags to define something...What's the difference

Is it the fact that you can slam everything in to one document as compared a transmission of organized concep[ts that have a particular meaning.

Wouldn't the xml document need to parse that out to derive that meaning?

I'm ALL for making my life easier...anyone got a code example?


Brett
2004-09-10
Shut Up! No Way...still problems though
It's a (painful) start...I think paper cut and lemon juice may be a better way...

This

CREATE PROC mySproc99
AS
SELECT 1 as Tag,
NULL as Parent,
Customers.CustomerID as [Customer!1!CustomerID],
NULL as [Order!2!OrderID]
FROM Customers
UNION ALL
SELECT 2,
1,
Customers.CustomerID,
Orders.OrderID
FROM Customers, Orders
WHERE Customers.CustomerID = Orders.CustomerID
ORDER BY [Customer!1!CustomerID], [Order!2!OrderID]
FOR XML EXPLICIT
GO

master..xp_cmdshell 'bcp "EXEC Northwind..mySproc99" queryout c:\temp\bcpOut.xml -Sservername -Usa -P -c -r -t'


Cause this

output
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
NULL
Starting copy...
SQLState = S1000, NativeError = 0
Error = [Microsoft][ODBC SQL Server Driver][SQL Server]Warning: Server data (3046 bytes) exceeds host-file field length (0 bytes) for field (1). Use prefix length, termination string, or a larger host-file field size. Truncation cannot occur for BCP out
put files.
SQLState = S1000, NativeError = 0
Error = [Microsoft][ODBC SQL Server Driver][SQL Server]Warning: Server data (3046 bytes) exceeds host-file field length (0 bytes) for field (1). Use prefix length, termination string, or a larger host-file field size. Truncation cannot occur for BCP out
put files.
SQLState = S1000, NativeError = 0
Error = [Microsoft][ODBC SQL Server Driver][SQL Server]Warning: Server data (3046 bytes) exceeds host-file field length (0 bytes) for field (1). Use prefix length, termination string, or a larger host-file field size. Truncation cannot occur for BCP out
put files.
SQLState = S1000, NativeError = 0
Error = [Microsoft][ODBC SQL Server Driver][SQL Server]Warning: Server data (3046 bytes) exceeds host-file field length (0 bytes) for field (1). Use prefix length, termination string, or a larger host-file field size. Truncation cannot occur for BCP out
put files.
SQLState = S1000, NativeError = 0
Error = [Microsoft][ODBC SQL Server Driver][SQL Server]Warning: Server data (3046 bytes) exceeds host-file field length (0 bytes) for field (1). Use prefix length, termination string, or a larger host-file field size. Truncation cannot occur for BCP out
put files.
SQLState = S1000, NativeError = 0
Error = [Microsoft][ODBC SQL Server Driver][SQL Server]Warning: Server data (3046 bytes) exceeds host-file field length (0 bytes) for field (1). Use prefix length, termination string, or a larger host-file field size. Truncation cannot occur for BCP out
put files.
SQLState = S1000, NativeError = 0
Error = [Microsoft][ODBC SQL Server Driver][SQL Server]Warning: Server data (3046 bytes) exceeds host-file field length (0 bytes) for field (1). Use prefix length, termination string, or a larger host-file field size. Truncation cannot occur for BCP out
put files.
SQLState = S1000, NativeError = 0
Error = [Microsoft][ODBC SQL Server Driver][SQL Server]Warning: Server data (3046 bytes) exceeds host-file field length (0 bytes) for field (1). Use prefix length, termination string, or a larger host-file field size. Truncation cannot occur for BCP out
put files.
SQLState = S1000, NativeError = 0
Error = [Microsoft][ODBC SQL Server Driver][SQL Server]Warning: Server data (3046 bytes) exceeds host-file field length (0 bytes) for field (1). Use prefix length, termination string, or a larger host-file field size. Truncation cannot occur for BCP out
put files.
SQLState = S1000, NativeError = 0
Error = [Microsoft][ODBC SQL Server Driver][SQL Server]Warning: Server data (3046 bytes) exceeds host-file field length (0 bytes) for field (1). Use prefix length, termination string, or a larger host-file field size. Truncation cannot occur for BCP out
put files.
SQLState = S1000, NativeError = 0
Error = [Microsoft][ODBC SQL Server Driver][SQL Server]Warning: Server data (3046 bytes) exceeds host-file field length (0 bytes) for field (1). Use prefix length, termination string, or a larger host-file field size. Truncation cannot occur for BCP out
put files.
SQLState = S1000, NativeError = 0
Error = [Microsoft][ODBC SQL Server Driver][SQL Server]Warning: Server data (1574 bytes) exceeds host-file field length (0 bytes) for field (1). Use prefix length, termination string, or a larger host-file field size. Truncation cannot occur for BCP out
put files.
NULL
12 rows copied.
Network packet size (bytes): 4096
Clock Time (ms.): total 16
NULL

rockmoose
2004-09-10
re: The Official XML Ranting Site
I'm a bit confused here Brett, You are asking me to answer "how to in XML" questions when in fact I meant the opposite.
The "rant" post was pure irony of course.
The other was a reply to David Mauri's request for a "better" non XML solution.
And in that example I did not use any XML stuff. n.b. of course i misspelled irrelevant and wrote relevant :-(

Anyway, let's try to keep this discussion productive and see if we all can benefit.
- What problems does XML solve ?
- Is XML a good alternative to other solutions ?, and why ?

So far I am inclined to answer none and no to the above questions.
none because xml doesn't "solve" any problem, it just tags it ;-).
no because it seems just plain stupid to tag every piece of data/info, without the "organized concept" the tags are useless anyway.

Claes W

rockmoose
2004-09-10
re: The Official XML Ranting Site
*LOL*
So what business problem are you solving Brett..
Getting XML out of the database ???

Very funny indeed.. ROFL

War Story:
In one project that required XML, we had a
@xml bit
parameter in all the procs.
We used @xml = 0 ourselves to make it work, and @xml = 1 when the business developers wanted to parse the xml through their parser.
All they did was build datasets anyway .. what a waste !

Brett
2004-09-10
That's not serious?
If migrating XL to and from things is not what it's meant for...then what...

I'm so confused...

Thanks good it's friday...

How whould XML markup a margarita?


rck
2005-08-19
re: The Official XML Ranting Site
I for one like XML, but prefer MySQL to MS SQL... :-) XML is cool for data exchange and web services, a relational database is cool for storage. Add transactions, give me my php PEAR classes and I am a happy man.

kiran
2006-08-31
re: The Official XML Ranting Site
Try using the same BCP from command line and it works amazingly.......I tried it and it worked but from query analyzer it gives problems

testeras
2006-12-30
Please help
People who know Bob Miller here?
need icq nubmer of bob miller

Leonardo
2006-12-31
Please Help with Windows Vista
Any one can help me with Windows Vista?
(Problems with install)