When using the 'WITH XMLNAMESPACES' Construct, the namespace declarations show up in each nested query of a 'SELECT FOR XML' statement.While it does produce a valid XML document, the results are not exactly pretty.Example query with a subselect:-------------------------------------------------------------------------WITH XMLNAMESPACES('http://test.com/customer' AS rt, 'http://test.com/customer/' AS rtc)SELECT Customer_id AS "@Customer_id" , (SELECT sub.Name AS "rt:Name" FROM Customer AS sub WHERE sub.Customer_id = Customer.Customer_id FOR XML PATH(''), type)FROM CustomerFOR XML PATH('rt:Customer')-------------------------------------------------------------------------(the sub-query is meant as an illustration)This query produces:-------------------------------------------------------------------------<rt:Customer xmlns:rtc="http://test.com/customer/types" xmlns:rt="http://test.com/customer" Customer_id="1"> <rt:Name xmlns:rtc=xmlns:rtc="http://test.com/customer/types" xmlns:rt="http://test.com/customer">Test Customer A</rt:Name></rt:Customer>-------------------------------------------------------------------------The 'redefinition' of the 'rtc' and 'rt' namespace-prefixes is 'overkill' in the produced result, and makes the result hard-to-read as well.The following result would be much better readable and also valid:-------------------------------------------------------------------------<rt:Customer xmlns:rtc="http://test.com/customer/types" xmlns:rt="http://test.com/customer" Customer_id="1"> <rt:Name>Test Customer A</rt:Name></rt:Customer>-------------------------------------------------------------------------
Category
Proposed Solution
Benefits
Other Benefits
Please wait...