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 =
Current version: (using .nodes() - method) [267 chars]
SELECT xml_data.value('@id','int') empID,
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]
XMLTABLE ('$d/dept/employee' passing doc as "d"
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:
[For those who are interested in the full spec of the XML/SQL Standard check out the detail information on the feedback]