|
it
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
ASP Amphasand, XML
--- <?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>" & vbcrlfobjRS.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 jbroder***@gmail.com wrote:
Show quote > I have a .asp document on my server it goes as follows You need to replace ampersands with &> --- > <?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? > -- Mike Brind Mike Brind wrote:
Show quote > jbroder***@gmail.com wrote: If you are using Google groups, you may not be able to see what I did.> > 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 & > > -- > Mike Brind Replace ampersands with the html character entity & amp ; (remove spaces) "Mike Brind" wrote ...
> If you are using Google groups, you may not be able to see what I did. I seem to remember having problems with XML once before for the same > Replace ampersands with the html character entity & amp ; (remove > spaces) 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 Rob Meade wrote:
> "Mike Brind" wrote ... This might prove useful in future, then:> > > 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 http://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references -- Mike Brind "Mike Brind" wrote ...
> This might prove useful in future, then: Hi Mike,> http://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references 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 <jbroder***@gmail.com> wrote in message
Show quote news:1153324567.570358.145740@75g2000cwc.googlegroups.com... You are going to run into all sorts of problems with this approach. Not> 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 > 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 >
Other interesting topics
|
|||||||||||||||||||||||