Home All Groups Group Topic Archive Search About


Author
19 Jul 2006 3:56 PM
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

Author
19 Jul 2006 9:09 PM
Mike Brind
jbroder***@gmail.com wrote:
Show quote
> 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?
>

You need to replace ampersands with &amp;

--
Mike Brind
Author
20 Jul 2006 7:33 AM
Mike Brind
Mike Brind wrote:
Show quote
> jbroder***@gmail.com wrote:
> > 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?
> >
>
> You need to replace ampersands with &amp;
>
> --
> Mike Brind

If you are using Google groups, you may not be able to see what I did.
Replace ampersands with the html character entity & amp ; (remove
spaces)
Author
20 Jul 2006 9:47 AM
Rob Meade
"Mike Brind" wrote ...

> If you are using Google groups, you may not be able to see what I did.
> Replace ampersands with the html character entity & amp ; (remove
> spaces)

I seem to remember having problems with XML once before for the same
reason - I believe there are other characters than just the & that cause
problems - I read somewhere before about having to define "ENTITIES" or
something?  That's about as far as it went before I just changed my code at
the time to change "&" to "and" - hehe

Rob
Author
20 Jul 2006 10:17 AM
Mike Brind
Rob Meade wrote:
> "Mike Brind" wrote ...
>
> > If you are using Google groups, you may not be able to see what I did.
> > Replace ampersands with the html character entity & amp ; (remove
> > spaces)
>
> I seem to remember having problems with XML once before for the same
> reason - I believe there are other characters than just the & that cause
> problems - I read somewhere before about having to define "ENTITIES" or
> something?  That's about as far as it went before I just changed my code at
> the time to change "&" to "and" - hehe
>
> Rob

This might prove useful in future, then:

http://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references

--
Mike Brind
Author
20 Jul 2006 10:52 AM
Rob Meade
"Mike Brind" wrote ...

Hi Mike,

Thanks for that - I tihnk it was the DTD bit that threw me in the past, my
XML knowledge was/is not the greatest, can do what I need to do but
typically its just config files and stuff as opposed to using anything else
clever to display the data in anyway...

Cheers for the link though - Wiki eh - seems to be taking over the
world....Wiki Wiki Web :o)

Rob
Author
21 Jul 2006 11:53 AM
Anthony Jones
<jbroder***@gmail.com> wrote in message
Show quote
news:1153324567.570358.145740@75g2000cwc.googlegroups.com...
> 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
>

You are going to run into all sorts of problems with this approach.  Not
only are you going to need to at least replace & and < with their
appropriate entities.  You would need to add an encoding attribute to the
XML declaration with matches the codepage currently being used by the
response object to encode the strings being written.

You also doing a lot of string contatention to make the output more
readable.  Why? Are users going to have to actually read the XML raw?

The Response.ContentType should be set to "text/xml".  If you are using
something like XMLHTTP to receive this XML it will be not automatically be
built into a DOM exposed as the responseXML property unless this content
type is set.  (and it's good practice to tell the HTTP requester the type of
resource you are sending.)

This is the approach I use:-

<%

        Dim oDOM
        Dim objConn
        Dim objRS
        Dim fldName
        Dim fldAddress

        Set oDOM = Server.CreateObject("MSXML2.DOMDocument.3.0")
        set objConn = Server.CreateObject("ADODB.Connection")
        set objRS= Server.CreateObject("ADODB.recordset")

        oDOM.loadXML  "<?xml version=""1.0"" standalone=""yes""
?><Restaurants/>"

        objconn.open
"Driver={SQLServer};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"

        Set fldName = objRS.Fields("RestaurantName")
        Set fldAddress = objRS.Fields("PremisesAddressLine1")
        Do Until objRS.EOF
                With
oDOM.documentElement.appendChild(oDOM.createElement("Restaurant"))
                    .appendChild(oDOM.createElement("Shop")).text =
fldName.Value
                    .appendChild(oDOM.createElement("Address")).text =
fldAddress.Value
                End With
                objRS.movenext
        Loop

        objRS.close
        objConn.close

        Response.ContentType = "text/xml"
        Response.CharSet = "UTF-8"
        oDOM.save Response

%>

It uses a DOM to build the XML which handles all the encoding etc correctly.
The resulting DOM is sent using UTF-8 encoding to the Response.

Show quote
>
> Jonathan Carl Broderick
>

AddThis Social Bookmark Button