【发布时间】:2018-01-12 09:18:39
【问题描述】:
我一直在使用sql 查询来生成xml 输出。
我已经设置了WITH XMLNAMESPACES(DEFAULT 'http://schemas.nav.gov.hu/2013/szamla', 'http://www.w3.org/2001/XMLSchema' as xs) 来设置命名空间。
WITH XMLNAMESPACES(DEFAULT 'http://schemas.nav.gov.hu/2013/szamla', 'http://www.w3.org/2001/XMLSchema' as xs)
SELECT CAST(getdate() as date) AS export_datuma
,@noOfResults AS export_szla_db
,@fromDate AS kezdo_ido
,@toDate AS zaro_ido
,@minInvoiceNo AS kezdo_szla_szam
,@maxInvoiceNo AS zaro_szla_szam
,@transactionXml AS [*]
FOR XML PATH('szamlak');
到目前为止,这工作正常,但在上面的查询中,变量 @transactionXml 已经是 xml 数据类型。所以上面这个查询的输出是这样的:
<szamlak xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.nav.gov.hu/2013/szamla">
<export_datuma>2018-01-12</export_datuma>
<export_szla_db>21</export_szla_db>
<kezdo_ido>2018-01-01</kezdo_ido>
<zaro_ido>2018-01-12</zaro_ido>
<kezdo_szla_szam>40003753</kezdo_szla_szam>
<zaro_szla_szam>70000219</zaro_szla_szam>
<szamla xmlns="">
<fejlec>
<szlasorszam>40003753</szlasorszam>
<szlatipus>Rechnung</szlatipus>
<szladatum>2018-01-02</szladatum>
<teljdatum>2017-12-21</teljdatum>
</fejlec>
...
我现在的问题是,我该如何避免每个 szamla 条目都获得属性 xmlns=""
<szamla xmlns="">
应该是这样的:
<szamla>
提前感谢您的帮助。
【问题讨论】:
标签: sql sql-server xml namespaces