|
|
|
SSC Rookie
      
Group: General Forum Members
Last Login: Thursday, January 31, 2013 3:06 AM
Points: 36,
Visits: 225
|
|
Hi all,
Its not that often we get thanked by MS for suggesting things that they want to do, but have been unable to implement due to a lack of knowledge/customer demand in an area which would not be know about unless you have worked with other RDMBS vendor systems. Without some help from fellow SQL Server professionals which do extensive work in XML - we would not get this useful functionality which MS want to give us and rid of us some non-intuitive proprietry commands. [Apologies in advance - if this is not the right place to place this feedback]
This functionality is the XMLTABLE command (XML/SQL - standard) which gives the ability to shred XML Documents quickly with a lower amount of code required than the current .nodes() or OPENXML processing methodology.
Take the following XML Example:
DECLARE @xml XML SELECT @xml = '<dept bldg="101"> <employee id="901"> <name> <first>John</first> <last>Doe</last> </name> <office>344</office> <salary currency="USD">55000</salary> </employee> <employee id="902"> <name> <first>Peter</first> <last>Pan</last> </name> <office>216</office> <phone>905-416-5004</phone> </employee> </dept> '
Current version: (using .nodes() - method) [267 chars]
SELECT xml_data.value('@id[1]','int') empID, name_info.value('first[1]','varchar(max)') first_name, name_info.value('last[1]','varchar(max)') last_name FROM @xml.nodes ('dept/employee') xml1(xml_data) CROSS APPLY xml_data.nodes ('name') name_list(name_info)
New version: (using Standardised XML/SQL XMLTABLE command) [217 chars]
SELECT X.* FROM emp, XMLTABLE ('$d/dept/employee' passing doc as "d" COLUMNS empID INTEGER PATH '@id', firstname VARCHAR(20) PATH 'name/first', lastname VARCHAR(25) PATH 'name/last') AS X
Personally I prefer the cleaner XMLTABLE version for the following reasons: * Standardised across all major RDBMS (IBM/ORACLE) etc [Easier to port from other systems to/from SQL Server] * Cleaner code produced - reduces need for redundant code blocks (.nodes() / .value), allows for many multiple paths to be used without requiring cross apply joins within the code. * Easier to read the XMLTABLE syntax - as its cleaner and matchs the paths more directly without having to cross-reference cross-apply joins.
Please show your support for this syntax as a requirement to our friends at MS; so we can get an improved way to quickly shred XML document in the future so this gets on the radar: https://connect.microsoft.com/SQLServer/feedback/details/644485/xmltable-output [For those who are interested in the full spec of the XML/SQL Standard check out the detail information on the feedback]
Thanks-in advance, D
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: Monday, May 13, 2013 11:21 AM
Points: 2,163,
Visits: 2,148
|
|
| Thanks for posting the suggestion, I think that would be great and have voted for it.
|
|
|
|
|
SSCertifiable
       
Group: General Forum Members
Last Login: Yesterday @ 9:55 PM
Points: 6,720,
Visits: 11,759
|
|
+1
__________________________________________________________________________________________________ There are no special teachers of virtue, because virtue is taught by the whole community. --Plato
Believe you can and you're halfway there. --Theodore Roosevelt
Everything Should Be Made as Simple as Possible, But Not Simpler --Albert Einstein
The significant problems we face cannot be solved at the same level of thinking we were at when we created them. --Albert Einstein
1 apple is not exactly 1/8 of 8 apples. Because there are no absolutely identical apples. --Giordy
|
|
|
|