By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,844 Members | 836 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,844 IT Pros & Developers. It's quick & easy.

How to generate pure XML page with ASP?

P: n/a
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
%>

Apr 11 '07 #1
Share this Question
Share on Google+
7 Replies


P: n/a
vu******@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....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
Apr 11 '07 #2

P: n/a
Option Explicit

you have the above set...
Set rsItem = Server.CreateObject("ADODB.Recordset")
ItemSQL = "...xxx..."
but I don't see these declared

Brian

Apr 11 '07 #3

P: n/a
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

Apr 11 '07 #4

P: n/a

<vu******@gmail.comwrote in message
news:11**********************@q75g2000hsh.googlegr 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

%>
Apr 11 '07 #5

P: n/a
On Apr 11, 5:13 pm, "Anthony Jones" <A...@yadayadayada.comwrote:
<vunet...@gmail.comwrote in message

news:11**********************@q75g2000hsh.googlegr 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
%>

Apr 13 '07 #6

P: n/a

<vu******@gmail.comwrote in message
news:11*********************@b75g2000hsg.googlegro ups.com...
On Apr 11, 5:13 pm, "Anthony Jones" <A...@yadayadayada.comwrote:
<vunet...@gmail.comwrote in message

news:11**********************@q75g2000hsh.googlegr 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 *.


Apr 13 '07 #7

P: n/a
On Apr 13, 11:30 am, "Anthony Jones" <A...@yadayadayada.comwrote:
<vunet...@gmail.comwrote in message

news:11*********************@b75g2000hsg.googlegro ups.com...On Apr 11, 5:13 pm, "Anthony Jones" <A...@yadayadayada.comwrote:
<vunet...@gmail.comwrote in message
>news:11**********************@q75g2000hsh.googleg 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.

Apr 13 '07 #8

This discussion thread is closed

Replies have been disabled for this discussion.