Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 SQL XML

Author  Topic 

Muj9
Yak Posting Veteran

75 Posts

Posted - 2014-07-23 : 06:33:09
<SOS xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.google.com">
<SRecord>
<PersonalXX xmlns="http://www.google.com">
<Column1>A</Column1>
<Per xmlns="http://www.google.com">
<Column2>B</Column2>
</Per>
<Column3>C</Column3>
</PersonalXX>
<Ref xmlns="http://www.google.com">
<Column4>D</Column4>
<Column5>E</Column5>
</Ref>
<Test xmlns="http://www.google.com">
<Column6>F</Column6>
<Column7>G</Column7>
<Column8>H</Column8>
</Test>
</SRecord>
</SOS>

Please somebody help me.
I have two issues.

1. i would like xmlns to appear before xmlns so it should look like this:-
<SOS xmlns="http://www.google.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >

2. the sub elements should not display xmlns="http://www.google.com".
<PersonalXX xmlns="http://www.google.com">
<Per xmlns="http://www.google.com">
<Ref xmlns="http://www.google.com">
<Test xmlns="http://www.google.com">


My desired output like:-

<SOS xmlns="http://www.google.com xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ">
<SRecord>
<PersonalXX>
<Column1>A</Column1>
<Per>
<Column2>B</Column2>
</Per>
<Column3>C</Column3>
</PersonalXX>
<Ref>
<Column4>D</Column4>
<Column5>E</Column5>
</Ref>
<Test>
<Column6>F</Column6>
<Column7>G</Column7>
<Column8>H</Column8>
</Test>
</SRecord>
</SOS>

Any ideas on this please?

Muj9
Yak Posting Veteran

75 Posts

Posted - 2014-07-23 : 06:40:12
i have used

WITH XMLNAMESPACES (default 'http://www.google.com')
--
Query and subqueries here which define the sub element for xml
--
for xml path('SRecord'),ROOT ('SOS'), ELEMENTS XSINIL

Go to Top of Page
   

- Advertisement -