How to get rid of extra xmlns:ns1 in sub element?

  • Run the following code in AdventureWorks DB

    ; WITH XMLNAMESPACES ( 'http://www.w3.org/TR/html4/' AS ns1 )

    SELECT ProductModelID as "@ns1:ProductModelID",

    Name as "@ns1:ProductModelName",

    (

    SELECT ProductID as "@ns1:ProductID",

    Name as "@ns1:ProductName"

    FROM Production. Product

    WHERE Production. Product. ProductModelID =

    Production. ProductModel. ProductModelID

    FOR XML PATH , type

    ) as "ns1:ProductNames"

    FROM Production. ProductModel

    WHERE ProductModelID= 7 or ProductModelID= 9

    FOR XML PATH ( 'ProductModelData' ), root ( 'root' )

    will generate:

    How to get rid of xmlns:ns1 = "http://www.w3.org/TR/html4/ " in element since it’s already declared in element?

  • You can't. It is a bug (of sorts). See the Microsoft Connect entry (265956): https://connect.microsoft.com/SQLServer/feedback/ViewFeedback.aspx?FeedbackID=265956

    Please vote and enter your comments.


    [font="Arial Narrow"](PHB) I think we should build an SQL database. (Dilbert) What color do you want that database? (PHB) I think mauve has the most RAM.[/font]

  • Thanks. Is it any way to workaround?

  • califny (8/26/2009)


    Thanks. Is it any way to workaround?

    None that I've found. We use XML extensively as a transport mechanism (i.e., to eliminate an extensive list of scalar parameters and/or to pass collections) to/from our stored procedures and the .Net business logic layer (BLL). Although the resulting XML is a bit "bloated", it is still valid XML. We have had no problems with either the .Net layer or with SQL Server XQuery.


    [font="Arial Narrow"](PHB) I think we should build an SQL database. (Dilbert) What color do you want that database? (PHB) I think mauve has the most RAM.[/font]

  • Thanks so much, JohnG.

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply