Hello everyone.
I am new to XML to extract data from SQL Server 2008 / 2012.
How do I remove/ignore the XML namespace in an xml file when querying the data with T-SQL ?
I would like to remove/ignore the PATH:
<ftc:HH xmlns:ftc="urn:Lenovo_laptop" xmlns:c="urn:tek_tips_guru">
TO:
<ftc:HH>
Below is my Query:
WITH XMLNAMESPACES ('urn:tek_tips_guru' as c, 'urn:Lenovo_laptop' as ftc)
SELECT TOP 1 NULL as N,
(
SELECT '100' as "c:ID",
'CompanyName' as "c:CompanyName",
'ContactTitle' as "c:ContactName/@ContactTitle",
'ContactName' as "c:ContactName/text()",
'PostalCode' as "c:Address/@ZIP",
'Addres' as "c:Address/c:Street",
'City' as "c:Address/c:City"
FOR XML PATH('c:xx'), TYPE
)
,
(SELECT '100' as "ftc:ID",
'CompanyName' as "ftc:CompanyName",
'ContactTitle' as "ftc:ContactName/@ContactTitle",
'ContactName' as "ftc:ContactName/text()",
'PostalCode' as "ftc:Address/@ZIP",
'Addres' as "ftc:Address/c:Street",
'City' as "ftc:Address/c:City"
FOR XML PATH('ftc:HH'), TYPE
) FOR XML PATH ('ALL') , ROOT('Company')
Below is he output of the above query but does not meet my expectation / desire output:
<Company xmlns:ftc="urn:Lenovo_laptop" xmlns:c="urn:tek_tips_guru">
<ALL>
<c:xx xmlns:ftc="urn:Lenovo_laptop" xmlns:c="urn:tek_tips_guru">
<c:ID>100</c:ID>
<c:CompanyName>CompanyName</c:CompanyName>
<c:ContactName ContactTitle="ContactTitle">ContactName</c:ContactName>
<c:Address ZIP="PostalCode">
<c:Street>Addres</c:Street>
<c:City>City</c:City>
</c:Address>
</c:xx>
<ftc:HH xmlns:ftc="urn:Lenovo_laptop" xmlns:c="urn:tek_tips_guru">
<ftc:ID>100</ftc:ID>
<ftc:CompanyName>CompanyName</ftc:CompanyName>
<ftc:ContactName ContactTitle="ContactTitle">ContactName</ftc:ContactName>
<ftc:Address ZIP="PostalCode">
<c:Street>Addres</c:Street>
<c:City>City</c:City>
</ftc:Address>
</ftc:HH>
</ALL>
</Company>
My expectation / Desire output would be:
<Company xmlns:ftc="urn:Lenovo_laptop" xmlns:c="urn:tek_tips_guru">
<ALL>
<c:xx xmlns:ftc="urn:Lenovo_laptop" xmlns:c="urn:tek_tips_guru">
<c:ID>100</c:ID>
<c:CompanyName>CompanyName</c:CompanyName>
<c:ContactName ContactTitle="ContactTitle">ContactName</c:ContactName>
<c:Address ZIP="PostalCode">
<c:Street>Addres</c:Street>
<c:City>City</c:City>
</c:Address>
</c:xx>
<ftc:HH>
<ftc:ID>100</ftc:ID>
<ftc:CompanyName>CompanyName</ftc:CompanyName>
<ftc:ContactName ContactTitle="ContactTitle">ContactName</ftc:ContactName>
<ftc:Address ZIP="PostalCode">
<c:Street>Addres</c:Street>
<c:City>City</c:City>
</ftc:Address>
</ftc:HH>
</ALL>
</Company>
Thanks for your help.
I am new to XML to extract data from SQL Server 2008 / 2012.
How do I remove/ignore the XML namespace in an xml file when querying the data with T-SQL ?
I would like to remove/ignore the PATH:
<ftc:HH xmlns:ftc="urn:Lenovo_laptop" xmlns:c="urn:tek_tips_guru">
TO:
<ftc:HH>
Below is my Query:
WITH XMLNAMESPACES ('urn:tek_tips_guru' as c, 'urn:Lenovo_laptop' as ftc)
SELECT TOP 1 NULL as N,
(
SELECT '100' as "c:ID",
'CompanyName' as "c:CompanyName",
'ContactTitle' as "c:ContactName/@ContactTitle",
'ContactName' as "c:ContactName/text()",
'PostalCode' as "c:Address/@ZIP",
'Addres' as "c:Address/c:Street",
'City' as "c:Address/c:City"
FOR XML PATH('c:xx'), TYPE
)
,
(SELECT '100' as "ftc:ID",
'CompanyName' as "ftc:CompanyName",
'ContactTitle' as "ftc:ContactName/@ContactTitle",
'ContactName' as "ftc:ContactName/text()",
'PostalCode' as "ftc:Address/@ZIP",
'Addres' as "ftc:Address/c:Street",
'City' as "ftc:Address/c:City"
FOR XML PATH('ftc:HH'), TYPE
) FOR XML PATH ('ALL') , ROOT('Company')
Below is he output of the above query but does not meet my expectation / desire output:
<Company xmlns:ftc="urn:Lenovo_laptop" xmlns:c="urn:tek_tips_guru">
<ALL>
<c:xx xmlns:ftc="urn:Lenovo_laptop" xmlns:c="urn:tek_tips_guru">
<c:ID>100</c:ID>
<c:CompanyName>CompanyName</c:CompanyName>
<c:ContactName ContactTitle="ContactTitle">ContactName</c:ContactName>
<c:Address ZIP="PostalCode">
<c:Street>Addres</c:Street>
<c:City>City</c:City>
</c:Address>
</c:xx>
<ftc:HH xmlns:ftc="urn:Lenovo_laptop" xmlns:c="urn:tek_tips_guru">
<ftc:ID>100</ftc:ID>
<ftc:CompanyName>CompanyName</ftc:CompanyName>
<ftc:ContactName ContactTitle="ContactTitle">ContactName</ftc:ContactName>
<ftc:Address ZIP="PostalCode">
<c:Street>Addres</c:Street>
<c:City>City</c:City>
</ftc:Address>
</ftc:HH>
</ALL>
</Company>
My expectation / Desire output would be:
<Company xmlns:ftc="urn:Lenovo_laptop" xmlns:c="urn:tek_tips_guru">
<ALL>
<c:xx xmlns:ftc="urn:Lenovo_laptop" xmlns:c="urn:tek_tips_guru">
<c:ID>100</c:ID>
<c:CompanyName>CompanyName</c:CompanyName>
<c:ContactName ContactTitle="ContactTitle">ContactName</c:ContactName>
<c:Address ZIP="PostalCode">
<c:Street>Addres</c:Street>
<c:City>City</c:City>
</c:Address>
</c:xx>
<ftc:HH>
<ftc:ID>100</ftc:ID>
<ftc:CompanyName>CompanyName</ftc:CompanyName>
<ftc:ContactName ContactTitle="ContactTitle">ContactName</ftc:ContactName>
<ftc:Address ZIP="PostalCode">
<c:Street>Addres</c:Street>
<c:City>City</c:City>
</ftc:Address>
</ftc:HH>
</ALL>
</Company>
Thanks for your help.