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
 Development Tools
 ASP.NET
 XML Parsing Error: not well-formed

Author  Topic 

meenus
Starting Member

10 Posts

Posted - 2012-01-25 : 21:00:10
dear support team,Advance thanks
in sql i wrote a procedure for xml dsiplay .

set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go




ALTER PROCEDURE [dbo].[sp_GetExplicitXML]
AS
--select * from products FOR XML explicit
SELECT 1 AS Tag,
NULL AS Parent,
c.catName as [Category!1!CatName],
NULL as [Product!2!ProdName],
NULL as [Product!2!Description]
FROM categories c
UNION ALL
SELECT 2 AS Tag,
1 AS Parent,
c.catName,
p.productName,
d.descText
FROM categories c, products p, descriptions d
WHERE c.catId = p.productCat AND p.productId = d.descProdId
ORDER BY [Category!1!CatName], [Product!2!ProdName]
FOR XML explicit




from vs2005 i tried to display as xml document.But i am getting error like
XML Parsing Error: not well-formed
Location: http://localhost:2386/XML/Default.aspx
Line Number 1, Column 2:



how can i solve this issue???VS code below

Dim sb As New StringBuilder
Dim dr As SqlDataReader
Dim xmlDoc As New XmlDocument
Dim objComm As New System.Data.SqlClient.SqlCommand
'objXML = Server.CreateObject("MSXML2.DOMDocument")
Dim objConn As New System.Data.SqlClient.SqlConnection("Data Source=11;Initial Catalog=XMLTest;Integrated Security=True")
If objConn.State = 1 Then objConn.Close()
objConn.Open()
objComm.Connection = objConn
objComm.CommandType = CommandType.StoredProcedure
objComm.CommandText = "sp_GetExplicitXML"
dr = objComm.ExecuteReader()
Do
While dr.Read()
sb.Append(dr.Item(0))
End While
Loop While dr.NextResult()
dr.Close()
Response.Write(sb(0))
Dim s As String = "222"
xmlDoc.LoadXml("<?xml version='1.0'?>" & sb.ToString)
xmlDoc.Save("C:\std.xml")
Response.ContentType = "text/xml"



in sql when i run the query i am getting the result like as follows3


<Category CatName="c1">
<Product ProdName="p1" Description="d1" />
</Category>



sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2012-01-26 : 13:01:36
Unlike normal XML, SQL's definition of "well-formed" does not require that it have a single root element. XML fragments are acceptable. That may be what is happening to you.

If you can post a sample output from the stored procedure that is throwing the error, people on the forum would be able to suggest the reasons and offer remedies.

If this is new work, consider using XML PATH instead of XML EXPLICIT. XML EXPLICIT is deprecated in SQL 2008 (slated for removal in a future version of SQL). XML PATH is simpler as well, and just as flexible.
Go to Top of Page
   

- Advertisement -