?
Solved

prevent XML namespace declarations from being added to every FOR XML section

Posted on 2009-05-07
1
Medium Priority
?
328 Views
Last Modified: 2013-11-08
I am using FOR XML in Microsoft SQL Server 2005 to generate XML from SQL.  I am using the PATH mode and the WITH XMLNAMESPACES clause.  The problem is that the XML namespace declarations are being added to every FOR XML section.  It does specify in this MSDN technical article that it will do that. http://msdn.microsoft.com/en-us/library/ms345137(SQL.90).aspx  I have pasted their example of what happens below.  See each <o:Order> line has the namespace declaration repeated.  I need to prevent this though in order for my XML file to be valid.  I only want this at the top element.  Any suggestions would be greatly appreciated.
Thank you,
Aana
<doc xmlns:o="urn:example.com/order" xmlns:c="urn:example.com/customer" 
     xmlns="urn:example.com/doc">
  <c:Customer ID="ALFKI">
    <c:Orders>
      <o:Order xmlns:o="urn:example.com/order"
         xmlns:c="urn:example.com/customer" xmlns="urn:example.com/doc" 
         OrderID="10643" />
      <o:Order xmlns:o="urn:example.com/order" 
         xmlns:c="urn:example.com/customer" xmlns="urn:example.com/doc" 
         OrderID="10692" />
      <o:Order xmlns:o="urn:example.com/order" 
         xmlns:c="urn:example.com/customer" xmlns="urn:example.com/doc" 
         OrderID="10702" />
      <o:Order xmlns:o="urn:example.com/order" 
         xmlns:c="urn:example.com/customer" xmlns="urn:example.com/doc" 
         OrderID="10835" />
      <o:Order xmlns:o="urn:example.com/order" 
         xmlns:c="urn:example.com/customer" xmlns="urn:example.com/doc" 
         OrderID="10952" />
      <o:Order xmlns:o="urn:example.com/order" 
         xmlns:c="urn:example.com/customer" xmlns="urn:example.com/doc" 
         OrderID="11011" />
    </c:Orders>
    <c:CompanyName>Alfreds Futterkiste</c:CompanyName>
    <c:ContactName 
       ContactTitle="Sales Representative">Maria Anders</c:ContactName>
    <c:Address ZIP="12209">
      <c:Street>Obere Str. 57</c:Street>
      <c:City>Berlin</c:City>
    </c:Address>
  </c:Customer>

Open in new window

0
Comment
Question by:anixon93
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 

Accepted Solution

by:
anixon93 earned 0 total points
ID: 24328304
Well, I figured how to get around this for my purposes.  Basically not including the namespaces in the SQL query and adding them later after my C# code processes the XML template.  
Thanks
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question