Re: A good argument for XML

From: <arthernan_at_hotmail.com>
Date: 13 Jul 2005 17:08:10 -0700
Message-ID: <1121299690.471819.175700_at_g49g2000cwa.googlegroups.com>


> actually use. I know for example that DataDirect Technologies has an
>XQuery implementation in beta that allows you to access your relational
>data and their SQL/XML implementation is already in 2.0.
>
>-- Jan Hidders

I looked at DataDirect Technologies website and I found a few examples on their XML/SQL implementation. Here is the link http://www.datadirect.com/developer/xquery/topics/sqlxml-xquery-nativexml/index.ssp

This is an attempt to justify in detail parts of what I have been "argumenting" in general. Here is a code example form the link above. I took some aliasing off that I thought would be superficial for the discussion:

select CustId,

	xmlelement(name "Customer",
		xmlattributes(CustId),
		xmlforest(c.Name, City),
		xmlelement(name projects,
		(select xmlagg(xmlelement(name project,
			xmlattributes(ProjId),
			xmlforest(p.name)))
		 from Projects p
		where p.CustId=c.CustId))) as "customer-projects"
from Customers c

On first impression this code looks complex and verbose. It is better than what XQuery provides. I can see already part of the source of animosity towards XML. Why are all the functions prefixed with XML. When SQL was developed there wasn't any SQLSELECT SQLFROM SQLWHERE. It's almost like they are drilling it into my head, and I end up typing more code. It is also harder to read. If the emphasis had been in hierarchical output instead the code could have looked like:

select CustId,

      node(name Customer, attribute CustId, value
           nodes(node(c.Name),
                 node(City),
                 (select aggnodes(node(name Project, attribute ProjID,
value node(p.Name))
                  from Projects p where p.CustId=c.CustId))) as
"customer-projects"

I personally think the second is easier to read. This is closer to a better syntactic solution than what I had seen before. Not my code example but the concept. One thing that still looks awkward to me is the combination of keywords and functions. I know people are familiar with SQL but select(select-clause, from-clause, where-clause, order-by, having......) could be better since functions do seem more hierarchical than statements. But again if we leave it to our marketing side of the brain......

Let's see how that would look:

select CustId,

      node("Customer", att(CustId),
           node(node(c.Name),
                node(City),
                selectnodes(
                      node("Project", att(ProjID), node(p.Name)),
                      Projects p,p.CustId=c.CustId)) as
"customer-projects"
from Customers c

I think this is easier to read, I am assuming overloading of the function node, and I eliminated the "name" keyword from the first parameter since Oracle does it on their xmlelement implementation. The overloading allows doing away with the difference between "xmlforest and "xmlelement". I also bound "select" and "xmlagg" together.

Anyway I am not trying to makeup my own language. I am going to look into possibly using XML/SQL.

Arturo Hernandez Received on Thu Jul 14 2005 - 02:08:10 CEST

Original text of this message