How to generate pure XML page with ASP?
How to generate pure XML page with ASP?
am 11.04.2007 16:35:55 von vunet.us
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/edit_item_xml.asp?itemi d=15
Line Number 2, Column 26:
-------------------------^
<% @ Language="VBScript" %>
<%
Option Explicit
Response.Buffer = True
Response.ContentType = "text/xml"
' Start XML document.
Response.Write "" & vbCrLf
%>
<%
Set rsItem = Server.CreateObject("ADODB.Recordset")
ItemSQL = "...xxx..."
rsItem.Open ItemSQL, adoCon
if not rsItem.eof then
Response.Write "" & vbCrLf
Response.Write ""&rsItem("ItemID")&"" &
vbCrLf
Response.Write "" & vbCrLf
end if
rsItem.close
set rsItem = nothing
set ItemSQL = nothing
set adoCon = nothing
%>
Re: How to generate pure XML page with ASP?
am 11.04.2007 18:26:53 von Daniel Crichton
vunet.us@gmail.com wrote on 11 Apr 2007 07:35:55 -0700:
> 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/edit_item_xml.asp?itemi d=15
> Line Number 2, Column 26:
> -------------------------^
This tends to mean there's an error in the code, and the ASP debugger is
spitting out where the problem is, but your browser is trying to parse it as
XML. View the source to see the error message, or comment out the line
generating the xml header.
Dan
Re: How to generate pure XML page with ASP?
am 11.04.2007 20:18:53 von Brian Staff
> Option Explicit
you have the above set...
> Set rsItem = Server.CreateObject("ADODB.Recordset")
> ItemSQL = "...xxx..."
but I don't see these declared
Brian
Re: How to generate pure XML page with ASP?
am 11.04.2007 23:13:48 von Anthony Jones
wrote in message
news:1176302155.562972.221560@q75g2000hsh.googlegroups.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/edit_item_xml.asp?itemi d=15
> Line Number 2, Column 26:
> -------------------------^
>
> <% @ Language="VBScript" %>
> <%
> Option Explicit
> Response.Buffer = True
> Response.ContentType = "text/xml"
>
> ' Start XML document.
> Response.Write "" & vbCrLf
> %>
>
> <%
> Set rsItem = Server.CreateObject("ADODB.Recordset")
> ItemSQL = "...xxx..."
> rsItem.Open ItemSQL, adoCon
> if not rsItem.eof then
>
> Response.Write "" & vbCrLf
> Response.Write ""&rsItem("ItemID")&"" &
> vbCrLf
> Response.Write "" & 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 ""
'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
%>
Re: How to generate pure XML page with ASP?
am 11.04.2007 23:16:11 von vunet.us
On Apr 11, 2:18 pm, Brian Staff
wrote:
> > Option Explicit
>
> you have the above set...
>
> > Set rsItem = Server.CreateObject("ADODB.Recordset")
> > ItemSQL = "...xxx..."
>
> but I don't see these declared
>
> Brian
they are declared. I just removed unnecessary stuff
Re: How to generate pure XML page with ASP?
am 13.04.2007 16:09:52 von vunet.us
On Apr 11, 5:13 pm, "Anthony Jones" wrote:
> wrote in message
>
> news:1176302155.562972.221560@q75g2000hsh.googlegroups.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/edit_item_xml. asp?itemid=15
> > Line Number 2, Column 26:
> > -------------------------^
>
> > <% @ Language="VBScript" %>
> > <%
> > Option Explicit
> > Response.Buffer = True
> > Response.ContentType = "text/xml"
>
> > ' Start XML document.
> > Response.Write "" & vbCrLf
> > %>
> >
> > <%
> > Set rsItem = Server.CreateObject("ADODB.Recordset")
> > ItemSQL = "...xxx..."
> > rsItem.Open ItemSQL, adoCon
> > if not rsItem.eof then
>
> > Response.Write "" & vbCrLf
> > Response.Write ""&rsItem("ItemID")&"" &
> > vbCrLf
> > Response.Write "" & 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 ""
>
> '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:
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 ""
'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
%>
Re: How to generate pure XML page with ASP?
am 13.04.2007 17:30:58 von Anthony Jones
wrote in message
news:1176473392.052605.82770@b75g2000hsg.googlegroups.com...
> On Apr 11, 5:13 pm, "Anthony Jones" wrote:
> > wrote in message
> >
> > news:1176302155.562972.221560@q75g2000hsh.googlegroups.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/edit_item_xml. asp?itemid=15
> > > Line Number 2, Column 26:
> > > -------------------------^
> >
> > > <% @ Language="VBScript" %>
> > > <%
> > > Option Explicit
> > > Response.Buffer = True
> > > Response.ContentType = "text/xml"
> >
> > > ' Start XML document.
> > > Response.Write "" & vbCrLf
> > > %>
> > >
> > > <%
> > > Set rsItem = Server.CreateObject("ADODB.Recordset")
> > > ItemSQL = "...xxx..."
> > > rsItem.Open ItemSQL, adoCon
> > > if not rsItem.eof then
> >
> > > Response.Write "" & vbCrLf
> > > Response.Write ""&rsItem("ItemID")&"" &
> > > vbCrLf
> > > Response.Write "" & 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 ""
> >
> > '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:
>
>
>
> 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 ""
>
> '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")
>
Try adding this code here:-
Else
AddElem oDOM.documentElement "Fail", "No Record for: " &
Request("id")
> end if
> rsItem.close
> set rsItem = nothing
> set ItemSQL = nothing
>
> Response.ContentType = "text/xml"
> Response.CharSet = "UTF-8"
> oDOM.save Response
> %>
>
I suspect the query isn't returning what you expect.
Also be explicit in using the Request object :- Request.QueryString("id") is
better.
I hope you will use a command object in production code. Concatenting data
from the client into a string that is executed as SQL leaves you open to SQL
injection attacks.
Use SELECT ItemID, Title instead of *.
Re: How to generate pure XML page with ASP?
am 13.04.2007 18:13:36 von vunet.us
On Apr 13, 11:30 am, "Anthony Jones" wrote:
> wrote in message
>
> news:1176473392.052605.82770@b75g2000hsg.googlegroups.com... > On Apr 11, 5:13 pm, "Anthony Jones" wrote:
> > > wrote in message
>
> > >news:1176302155.562972.221560@q75g2000hsh.googlegroups.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/edit_item_xml. asp?itemid=15
>
>
>
> > > > Line Number 2, Column 26:
> > > > -------------------------^
>
> > > > <% @ Language="VBScript" %>
> > > > <%
> > > > Option Explicit
> > > > Response.Buffer = True
> > > > Response.ContentType = "text/xml"
>
> > > > ' Start XML document.
> > > > Response.Write "" & vbCrLf
> > > > %>
> > > >
> > > > <%
> > > > Set rsItem = Server.CreateObject("ADODB.Recordset")
> > > > ItemSQL = "...xxx..."
> > > > rsItem.Open ItemSQL, adoCon
> > > > if not rsItem.eof then
>
> > > > Response.Write "" & vbCrLf
> > > > Response.Write ""&rsItem("ItemID")&"" &
> > > > vbCrLf
> > > > Response.Write "" & 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 ""
>
> > > '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:
>
> >
>
> > 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 ""
>
> > '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")
>
> Try adding this code here:-
>
> Else
>
> AddElem oDOM.documentElement "Fail", "No Record for: " &
> Request("id")
>
> > end if
> > rsItem.close
> > set rsItem = nothing
> > set ItemSQL = nothing
>
> > Response.ContentType = "text/xml"
> > Response.CharSet = "UTF-8"
> > oDOM.save Response
> > %>
>
> I suspect the query isn't returning what you expect.
>
> Also be explicit in using the Request object :- Request.QueryString("id") is
> better.
>
> I hope you will use a command object in production code. Concatenting data
> from the client into a string that is executed as SQL leaves you open to SQL
> injection attacks.
>
> Use SELECT ItemID, Title instead of *.
i am embarrased to say but this error happens when item does not
exist, otherwise the code works well. thank you for the hint. you are
great.