Visual Basic .NET » Database Programming
XML and Amphasand & -- jbroderick --


I have a .asp document on my server it goes as follows
---
<?xml version="1.0" standalone='yes'?>
<Restaurants>
<%
Dim objConn
Dim objRS

set objConn = Server.CreateObject("ADODB.Connection")
set objRS = server.CreateObject("ADODB.recordset")

objconn.open "Driver={SQL Server};Server=localhost;Uid=user;Pwd=pass;Database=me"
objRS.activeconnection = objConn
objRS.open "SELECT RestaurantName, PremisesAddressLine1 as Address FROM tblRestaurantAccounts WHERE franchiseID= 16 and accountstatus=0"

do until objRS.eof
response.write vbtab & "<Restaurant>" & vbcrlf
response.write vbtab & vbtab & "<Shop>" &
objRS.fields("Restaurantname").value & "</Shop>" & vbcrlf
response.write vbtab & vbtab & "<Address>" &
objRS.fields("address").value & "</Address>" & vbcrlf
response.write vbtab & "</Restaurant>" & vbcrlf
objRS.movenext
loop

objRS.close
objConn.close

set objRS = nothing
set objConn = nothing
%>
</Restaurants>
---

the only problem is that it chokes when it gets a record entry that contains a "&". what code do i need or what modifications to my code to let this .asp document display a "well-formed" xml document?

thanks for your help

Jonathan Carl Broderick

-- ClintonFarleigh --


You need to replace & with &amp; Calling Server.HtmlEncode on your data strings should do this for you.

-- TeemuKeiski --


'&' should be represented as '&amp;' in XML document.

-------------------------------------------------
Teemu Keiski ASP.NET MVP, AspInsider Finland, EU
http://blogs.aspadvice.com/joteke 


-----Original Message-----
From: aspnet
XML and Amphasand &
I have a .asp document on my server it goes as follows
---
<?xml version="1.0" standalone='yes'?>
<Restaurants>
<%
Dim objConn
Dim objRS

set objConn = Server.CreateObject("ADODB.Connection")
set objRS = server.CreateObject("ADODB.recordset")

objconn.open "Driver={SQL Server};Server=localhost;Uid=user;Pwd=pass;Database=me"
objRS.activeconnection = objConn
objRS.open "SELECT RestaurantName, PremisesAddressLine1 as Address FROM tblRestaurantAccounts WHERE franchiseID= 16 and accountstatus=0"

do until objRS.eof
response.write vbtab & "<Restaurant>" & vbcrlf
response.write vbtab & vbtab & "<Shop>" &
objRS.fields("Restaurantname").value & "</Shop>" & vbcrlf
response.write vbtab & vbtab & "<Address>" &
objRS.fields("address").value & "</Address>" & vbcrlf
response.write vbtab & "</Restaurant>" & vbcrlf
objRS.movenext
loop

objRS.close
objConn.close

set objRS = nothing
set objConn = nothing
%>
</Restaurants>
---

the only problem is that it chokes when it gets a record entry that contains a "&". what code do i need or what modifications to my code to let this .asp document display a "well-formed" xml document?

thanks for your help

Jonathan Carl Broderick


-- davidj --


Wherever there is an &, change it to &amp;

& = &amp;

-- davidj --


Replace the & with &amp;

davidj
www.davidj.org 


[Submit Comment]Home