Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP General > How to generate pure XML page with ASP?

Reply
Thread Tools

How to generate pure XML page with ASP?

 
 
vunet.us@gmail.com
Guest
Posts: n/a
 
      04-11-2007
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
%>

 
Reply With Quote
 
 
 
 
Daniel Crichton
Guest
Posts: n/a
 
      04-11-2007
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....asp?itemid=15
> Line Number 2, Column 26: <font face="Arial" size=2>
> -------------------------^


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


 
Reply With Quote
 
 
 
 
Anthony Jones
Guest
Posts: n/a
 
      04-11-2007

<> 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

%>


 
Reply With Quote
 
vunet.us@gmail.com
Guest
Posts: n/a
 
      04-11-2007
On Apr 11, 2:18 pm, Brian Staff <brianstaff AT [NoSpam]cox DOT net>
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

 
Reply With Quote
 
vunet.us@gmail.com
Guest
Posts: n/a
 
      04-13-2007
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
%>

 
Reply With Quote
 
Anthony Jones
Guest
Posts: n/a
 
      04-13-2007

<> wrote in message
news: ups.com...
> 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")
>


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 *.




 
Reply With Quote
 
vunet.us@gmail.com
Guest
Posts: n/a
 
      04-13-2007
On Apr 13, 11:30 am, "Anthony Jones" <A...@yadayadayada.com> wrote:
> <vunet...@gmail.com> wrote in message
>
> news: ups.com...> On Apr 11, 5:13 pm, "Anthony Jones" <A...@yadayadayada.com> wrote:
> > > <vunet...@gmail.com> wrote in message

>
> > >news: roups.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")

>
> 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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Pure space directly inside div ignored, but pure space directlyinside span honored liketofindoutwhy@gmail.com HTML 4 03-29-2008 06:06 PM
DHTML tables generate R6025 pure virtual function call error in IE6 any ideas?? Steve Javascript 3 09-15-2006 04:07 PM
Pure functions still pure after definition Todd Aspeotis C++ 3 05-30-2005 03:53 AM
ASP XML Support - Generate XML string from FORM DATA based on XML schema Matt ASP General 3 04-23-2004 07:12 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57