Click to See Complete Forum and Search --> : [RESOLVED] XML Creation


bulgarian388
12-18-2006, 02:38 PM
Hi guys, I am trying to create an ASP file that generates and outputs XML code to the browser. I am trying to make a password comparison via XMLHttpRequest(), and get the results from the asp page. Problem is that the code is working, it is outputting the file structure I expect it to, but Firefox says it's invalid markup, and also it doesn't display like other pure XML documents I have. Here is the code I am using:


response.Expires = 0
response.ExpiresAbsolute = now() - 1
response.AddHeader "pragma","no-cache"
response.AddHeader "cache-control","private"
response.CacheControl = "no-cache"

keyId = session("keyId")
sessionName = session("sessionName")
sessionLevel = session("sessionLevel")
'if keyId = "" or isnull(keyId) then
' response.Redirect("../")
'end if

currentPassword = request.QueryString("currentPassword")

Set A = server.CreateObject("ADODB.Connection")
A.Open(" :) ")

Set A1 = A.Execute("SELECT password FROM membershipManagement WHERE keyId = '" & keyId & "'")
If Not A1.EOF Then
password = A1("password")
End If
A1.Close()
Set A1 = Nothing

A.Close()
Set A = Nothing

if currentPassword = password then
isValid = true
else
isValid = false
end if

response.Write("<?xml version=" & chr(34) & "1.0" & chr(34) & " encoding=" & chr(34) & "iso-8859-1" & chr(34) & "?>" & VbCrLf)
response.Write("<results>" & VbCrLf)
response.Write(" <isValid>" & isValid & "</isValid>" & VbCrLf)
response.Write("</results>" & VbCrLf)

response.End()


And I get this as output:


<?xml version="1.0" encoding="iso-8859-1"?>
<results>
<isValid>True</isValid>
</results>


Could someone point me to the right direction, pretty please? ;) ;) ;)

Thanks in advance!

russell
12-18-2006, 03:37 PM
u left out

</xml>

<xml version="1.0" encoding="iso-8859-1">
<results>
<isValid>True</isValid>
</results>
</xml>

bulgarian388
12-18-2006, 03:50 PM
Well, I tried that, and it didn't work. As far as I am aware, with my minor knowledge of XML, the <?xml ?> head tag doesn't need to be closed. Or at least my other XML docs, site maps, don't.

Any other suggestions?

Thanks in advance, again!

bulgarian388
12-18-2006, 05:35 PM
Okay, figured it out. For anyone curious for their own use:

Set the Content Type to "application/xml"


response.ContentType = "application/xml"


The do you database query stuff and write out the XML structure:


response.Write("<?xml version=" & chr(34) & "1.0" & chr(34) & " encoding=" & chr(34) & "utf-8" & chr(34) & "?>" & VbCrLf)
response.Write("<databaseResult>" & VbCrLf)
response.Write(" <passwordResult>" & password & "</passwordResult>" & VbCrLf)
response.Write("</databaseResult>" & VbCrLf)


And it works. :)