I am generating a very large dataset into an XML file to send to an external web service. This file is about 20 megabytes and has a validation error somewhere near character 18995504 of the only line in the file.
DECLARE @Text nvarchar(MAX)
SET @Text = (SELECT xml FROM (...) multiLeveledQueryFromHell)
SET @Text = '<root xmlns="urn:examplenamespace" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:schemaname urn:schemaurl">' + @Text + '</root>'
EXECUTE WriteToFile(@Filename, @Text)
The conversion from xml to nvarchar(MAX) leaves me with a string like <root ...><elements>...</elements></root>
. I want to get it in the multi-line tabbed version
<root ...>
<elements>
...
</elements>
</root>
How do I do this using SQL Server by itself or with a minimum of new tools?