On Apr 11, 5:13 pm, "Anthony Jones" <A...@yadayadayada.com> wrote:
> <vunet...@gmail.com> wrote in message
>
> news: oups.com...
>
>
>
> > How to generate pure XML page with ASP?
> > This try gave me an error:
>
> > XML Parsing Error: not well-formed
> > Location:http://www.worldincatalog.com/manage....asp?itemid=15
> > Line Number 2, Column 26: <font face="Arial" size=2>
> > -------------------------^
>
> > <% @ Language="VBScript" %>
> > <%
> > Option Explicit
> > Response.Buffer = True
> > Response.ContentType = "text/xml"
>
> > ' Start XML document.
> > Response.Write "<?xml version=""1.0""?>" & vbCrLf
> > %>
> > <!-- #Include file="adocon.inc" -->
> > <%
> > Set rsItem = Server.CreateObject("ADODB.Recordset")
> > ItemSQL = "...xxx..."
> > rsItem.Open ItemSQL, adoCon
> > if not rsItem.eof then
>
> > Response.Write "<ItemXML>" & vbCrLf
> > Response.Write "<ItemID>"&rsItem("ItemID")&"</ItemID>" &
> > vbCrLf
> > Response.Write "</ItemXML>" & vbCrLf
>
> > end if
> > rsItem.close
> > set rsItem = nothing
> > set ItemSQL = nothing
> > set adoCon = nothing
> > %>
>
> Build the XML using a DOM. There so many pitfuls to writing XML directly to
> Response it just isn't worth it in most cases:-
>
> <%
>
> Dim oDOM : Set oDOM = Server.CreateObject("MSXML2.DOMDocument.3.0")
> oDOM.LoadXML "<ItemXML />"
>
> 'Recordset stuff here
>
> AddElem oDOM.documentElement, "ItemID", rsItem("ItemID")
>
> Response.ContentType = "text/xml"
> Response.CharSet = "UTF-8"
> oDOM.save Response
>
> Function AddElem(roParent, rsName, rvntValue)
> Set AddElem = roParent.ownerDocument.createElement(rsName)
> roParent.appendChild AddElem
> If Not IsNull(rvntValue) AddElem.Text = rvntValue
> End Function
>
> %>
this generates the output:
<ItemXML/>
What's wrong?
<% @ Language="VBScript" %>
<%
Function AddElem(roParent, rsName, rvntValue)
Set AddElem = roParent.ownerDocument.createElement(rsName)
roParent.appendChild AddElem
If Not IsNull(rvntValue) AddElem.Text = rvntValue
End Function
Dim oDOM : Set oDOM = Server.CreateObject("MSXML2.DOMDocument.
3.0")
oDOM.LoadXML "<ItemXML />"
'included adoCon
Set rsItem = Server.CreateObject("ADODB.Recordset")
ItemSQL = "SELECT * FROM TABLE WHERE ItemID = '" & request("id") &
"';"
rsItem.Open ItemSQL, adoCon
if not rsItem.eof then
AddElem oDOM.documentElement, "ItemID", rsItem("ItemID")
AddElem oDOM.documentElement, "Title", rsItem("Title")
end if
rsItem.close
set rsItem = nothing
set ItemSQL = nothing
Response.ContentType = "text/xml"
Response.CharSet = "UTF-8"
oDOM.save Response
%>