Solved

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

Posted on 2009-05-07
1
321 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
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Shoutout to Emily Plummer (http://www.experts-exchange.com/members/eplummer26.html) for giving me this article! She did most of it, I just finished it up and posted it for her :)    Introduction In a previous article (http://www.experts-exchang…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

708 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now