I'm fine tuning a web app that calls SOAP services backed by SQL stored procedure calls. Typically the stored procs generate XML that becomes part of the SOAP response, and that XML has many superfluous xmlns namespace declarations. In pathological cases this can be 30% or more of the char encoded XML measured in bytes, e.g.:
<GetFooResponse xmlns="http://service.url/">
<GetFooResult>
<FooItems xmlns="http://www.thisisalongishurl.com/schema12345/version12345">
<Item xmlns="http://www.thisisalongishurl.com/schema12345/version12345" data="foo" />
<Item xmlns="http://www.thisisalongishurl.com/schema12345/version12345" data="foo" />
<Item xmlns="http://www.thisisalongishurl.com/schema12345/version12345" data="foo" />
<Item xmlns="http://www.thisisalongishurl.com/schema12345/version12345" data="foo" />
<Item xmlns="http://www.thisisalongishurl.com/schema12345/version12345" data="foo" />
</FooItems >
</GetFooResult>
</GetFooResponse>
The SQL I'm using to generate XML typically follows this pattern:
WITH XMLNAMESPACES(DEFAULT 'http://www.this开发者_如何转开发isalongishurl.com/schema12345/version12345')
SELECT
[Name],
[Value]
FROM
[Foo]
FOR XML PATH('Item'),
TYPE,
ROOT('FooItems');
Is there any way to avoid the generation of superfluous xmlns namespace declations on each Item XML element?
thanks.
WITH XMLNAMESPACES(
'http://www.thisisalongishurl.com/schema12345/version12345' AS short,
DEFAULT 'http://service.url/'
),
[Foo] ([short:Name], [short:Value]) AS
(
SELECT 'testName', 'testValue'
)
SELECT *
FROM [Foo]
FOR XML PATH('Item'),
TYPE,
ROOT('FooItems')
returns
<FooItems xmlns="http://service.url/" xmlns:short="http://www.thisisalongishurl.com/schema12345/version12345">
<Item>
<short:Name>testName</short:Name>
<short:Value>testValue</short:Value>
</Item>
</FooItems>
精彩评论