2

I exported data from SQL Server to XML file like this :

USE Northwind;

SELECT * FROM Products FOR XML PATH;

For NULL value , it returned xsi:nil="true".

For example: <ProductName xsi:nil="true"/>

Can I export without the xsi:nil="true" ?

But I do want to have tag name like : <ProductName /> or <ProductName></ProductName>

Can someone tell me how to export like this?

Thanks.

1
  • hi,what is the database that u using? Commented Oct 13, 2013 at 13:49

1 Answer 1

4

You can try something like this...

SELECT * FROM Products
    FOR XML RAW('customer'), ROOT('customers') 

ROOT clause in for XML statement creates root element for your XML document to create a well formed XML document , IF you want all the values in Elements you can add the Elements Clause in your FOR XML statement, which would be something like this.

SELECT * FROM Products
FOR XML RAW('customer'), ROOT('customers'), Elements

Now if you add XSINIL clause at the end of it only then it will you the ELEMENTS will null values as , otherwise it will not return the element at all. Which will be something like this..

SELECT * FROM Products
FOR XML RAW('customer'), ROOT('customers'), Elements XSINIL 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.