Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ASP produced XML File + White space issue

Status
Not open for further replies.

JimFL

Programmer
Jun 17, 2005
131
GB
I am producing an XML file through ASP to pass to flash. I have generated the tables in SQL Server. I use the following code to connect to the database and output to an XML file. It works fine for one table that I have but not the other two.
I get an error saying that whitespace is not allowed at this location.

RECORD><RECORD><marketID>121</marketID><market>Slovakia</market></RECORD><RECORD&g...
m"></RECORD>
+ <RECORD>

Can anybody help? What does it mean by Whitespace? in the <marketID>flags? What can I do to solve this?

My ASP code is as follows:
<%
response.ContentType="text/xml"
response.write("<?xml version='1.0' encoding='ISO-8859-1'?>")

'The code below must be modified according to your database connection
'It is just a simple ADO Recordset declaration and opening
Set rs = Server.CreateObject("ADODB.Recordset")
rs.ActiveConnection = MM_DB_STRING

sql = "select marketID,market from MARKETS"
rs.Open sql
'End of modified code

response.write("<ROOT>")
while not rs.Eof
response.write("<RECORD>")
for i=0 to rs.fields.count -1
if rs.fields(i).value<>"" then
response.write("<"&rs.Fields(i).Name&">"&trim(rs.Fields(i).Value)&"</"&rs.Fields(i).Name&">")
else
response.write("<"&rs.Fields(i).Name&"/>")
end if
next
response.write("</RECORD>")
rs.moveNext
wend
response.write("</ROOT>")


rs.close
set rs = nothing
%>

 
Not sure where the location the error occurs even with your description. This improves the rigor of the conditional see if it takes care of the conern.
>[tt]if rs.fields(i).value<>"" then[/tt]
[tt] if [red]trim([/red]rs.fields(i).value[red])[/red]<>"" then[/tt]
 
thanks but I have just solved my issue by placing the CDATA tag around the internal xml tags.

response.write("<"&rs.Fields(i).Name&">"&trim(rs.Fields(i).Value)&"</"&rs.Fields(i).Name&">")

becomes..

response.write("<"&rs.Fields(i).Name&"><![CDATA["&(rs.Fields(i).Value)&"]]></"&rs.Fields(i).Name&">")

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top