I am having problems with the namespaces when using XML type data
inside a for XMLpath..
here is the first example
----
--
WITH XMLNAMESPACES(DEFAULT 'http://www.ratdog.com/example' )
select
'karl' as "name",
(select
'1' as "mine/one",
'2' as "mine/two"
for xml path('child'), type
)
for xml path('outer'), type
----
<outer xmlns="http://www.ratdog.com/example">
<name>karl</name>
<child xmlns="http://www.ratdog.com/example">
<mine>
<one>1</one>
<two>2</two>
</mine>
</child>
</outer>
----
you'll notice that it added the namespace to the "inner child" :),
which i'd rather it not do but at least its correct and it works.
however in the following example i put the "inner child" sql inside a
function as show :
----
create function dbo.testfunc()
returns XML
as
begin
return
(
select
'1' as "mine/one",
'2' as "mine/two"
for xml path('child'), type
)
end
WITH XMLNAMESPACES(DEFAULT 'http://www.ratdog.com/example' )
select
'karl' as "name",
dbo.testfunc()
for xml path('outer'), type
---
<outer xmlns="http://www.ratdog.com/example">
<name>karl</name>
<child xmlns="">
<mine>
<one>1</one>
<two>2</two>
</mine>
</child>
</outer>
---
and it puts the namespace as "", which i definately don't want.. i
don't want that clause in there at all
how can i get rid of it? or achieve a suitable workaround.
KarlNote that the function creates a document that has no namespace associated
with it. Since you include it in one that has the prefix, we have to
undeclare the default prefix.
So if you want to have the function have the same default namespace, you
need to use the WITH clause in the function.
And no, we currently do not remove the declarations on the inner level if
they are redundant...
Best regards
Michael
<klumsy@.xtra.co.nz> wrote in message
news:1144364933.977174.287100@.u72g2000cwu.googlegroups.com...
> I am having problems with the namespaces when using XML type data
> inside a for XMLpath..
> here is the first example
> ----
--
> WITH XMLNAMESPACES(DEFAULT 'http://www.ratdog.com/example' )
> select
> 'karl' as "name",
> (select
> '1' as "mine/one",
> '2' as "mine/two"
> for xml path('child'), type
> )
> for xml path('outer'), type
> ----
> <outer xmlns="http://www.ratdog.com/example">
> <name>karl</name>
> <child xmlns="http://www.ratdog.com/example">
> <mine>
> <one>1</one>
> <two>2</two>
> </mine>
> </child>
> </outer>
> ----
> you'll notice that it added the namespace to the "inner child" :),
> which i'd rather it not do but at least its correct and it works.
> however in the following example i put the "inner child" sql inside a
> function as show :
> ----
> create function dbo.testfunc()
> returns XML
> as
> begin
> return
> (
> select
> '1' as "mine/one",
> '2' as "mine/two"
> for xml path('child'), type
> )
> end
> WITH XMLNAMESPACES(DEFAULT 'http://www.ratdog.com/example' )
> select
> 'karl' as "name",
> dbo.testfunc()
> for xml path('outer'), type
> ---
> <outer xmlns="http://www.ratdog.com/example">
> <name>karl</name>
> <child xmlns="">
> <mine>
> <one>1</one>
> <two>2</two>
> </mine>
> </child>
> </outer>
> ---
> and it puts the namespace as "", which i definately don't want.. i
> don't want that clause in there at all
> how can i get rid of it? or achieve a suitable workaround.
> Karl
>
Thursday, March 8, 2012
childitem issues with xmlnamespaces and for xml path
Labels:
childitem,
database,
datainside,
default,
example-with,
microsoft,
mysql,
namespaces,
oracle,
path,
server,
sql,
type,
xml,
xmlnamespaces,
xmlpath
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment