sql server - How can I use a WITH XMLNAMESPACES clause with correlated queries? -


i'm trying use for xml feature of sql server generate xml, specific namespaces.

my target xml should like:

<ns1:customerinvoices xmlns:ns1="urn:example.com:invoice:01.00">   <customerinvoice>     <header>       <orderdate>2001-11-13t00:00:00</orderdate>       <salesordernumber>so44643</salesordernumber>     </header>     <lines>       <linetotal>3578.270000</linetotal>       <unitprice>3578.2700</unitprice>       <orderqty>1</orderqty>     </lines>   </customerinvoice>   <customerinvoice>...(abbreviated)...</customerinvoice> </ns1:customerinvoices> 

the problem have, when use with xmlnamespaces clause, namespace declaration appears on lots of child nodes, third party consumer of xml "prefer not get", i.e. i'm doing like:

use adventureworks2008  ;with xmlnamespaces ('urn:example.com:invoice:01.00' ns1)  select      (select     hdr.orderdate,                         hdr.salesordernumber             xml path (''), type) header,             (select     line.linetotal,                         line.unitprice,                         line.orderqty                     sales.salesorderdetail  line                    line.salesorderid = hdr.salesorderid             xml path (''), type) lines         sales.salesorderheader  hdr        hdr.modifieddate = '2001-11-20'  xml path('customerinvoice'), root('ns1:customerinvoices')  

which gives:

<ns1:customerinvoices xmlns:ns1="urn:example.com:invoice:01.00">   <customerinvoice>     <header>       <orderdate xmlns:ns1="urn:example.com:invoice:01.00">2001-11-13t00:00:00</orderdate>       <salesordernumber xmlns:ns1="urn:example.com:invoice:01.00">so44643</salesordernumber>     </header>     <lines>       <linetotal xmlns:ns1="urn:example.com:invoice:01.00">3578.270000</linetotal>       <unitprice xmlns:ns1="urn:example.com:invoice:01.00">3578.2700</unitprice>       <orderqty xmlns:ns1="urn:example.com:invoice:01.00">1</orderqty>     </lines>   </customerinvoice>   <customerinvoice>...(abbreviated)...</customerinvoice> </ns1:customerinvoices> 

is possible tweak query namespaces correct, or have load "something else" remove redundant namespace declarations?

you're not alone.

http://connect.microsoft.com/sqlserver/feedback/details/265956/suppress-namespace-attributes-in-nested-select-for-xml-statements

i suggest upvoting improvement.

there work around listed @ connect site above:

http://www.olcot.co.uk/sql-blogs/suppressing-namespace-attributes-in-nested-select-statements-when-using-for-xml-workaround


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

java - Using an Integer ArrayList in Android -