Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Import/Export (DTS) and Replication (2000)
 FOR XML Output Not Well Formed XML

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2002-09-04 : 11:21:18
Ben writes "I am trying to export a query to XML following the SQLXML Trans-SQL syntax...

I have the following SELECT statement:

SELECT 1 as Tag,
NULL as Parent,
Customers.CustomerID as [Customer!1!CustomerID],
NULL as [Order!2!OrderID]
FROM Customers

UNION ALL
SELECT 2,
1,
Customers.CustomerID,
Orders.OrderID
FROM Customers, Orders
WHERE Customers.CustomerID = Orders.CustomerID
ORDER BY [Customer!1!CustomerID], [Order!2!OrderID]
FOR XML EXPLICIT

You might recognize this from the MS Example for Using EXPLICIT Mode...

Here's the problem, the output is not well-formed XML. In fact, it generates incomplete duplicate elements depending upon the row that it limited out on.

Here's an example of the first row's output:
<Customer CustomerID="ALFKI"><Order OrderID="10643"/><Order OrderID="10692"/><Order OrderID="10702"/><Order OrderID="10835"/><Order OrderID="10952"/><Order OrderID="11011"/></Customer><Customer CustomerID="ANATR"><Order OrderID="10308"/><Order OrderID="106

As you can see it is truncating that row and produces badly formatted XML file, too...

Am I missing some configuration set up with SQL Server that enables this Trans-SQL option?

TIA,

Ben Cramer
iPath Solutions"

jasper_smith
SQL Server MVP &amp; SQLTeam MVY

846 Posts

Posted - 2002-09-04 : 15:12:14
I assume you mean truncating in query analyser ?
Two things
1) place dbcc traceon(257) before the statement and return results in text view. This trace flag makes the xml look nice.
2) In QA>Tools>Options>Results increase the maximum characters per column



HTH
Jasper Smith
Go to Top of Page
   

- Advertisement -