|
-
Nov 21st, 2006, 10:56 AM
#1
Thread Starter
Lively Member
create an XML file from ASP
hi,
I do this all the time in VB, and indeed read xml files from ASP but cant find info on creatin ght eXML files from ASP,
asll i want to do is create a really simple XML file from scratch from ASP with a top element "MESSAGE" then 2 child elements "File" and "File Name"
any ideas any1?
many thanks.
-
Nov 21st, 2006, 11:03 AM
#2
Addicted Member
Re: create an XML file from ASP
What do you mean you can't create XML files from ASP? I do it all the time. What exactly is it that you can't do? What is it that isn't happening? Are you using the MSXML objects, or? Is it just a file saving thing - that the file doesn't get saved to disk, or? What errors, if any, are being raised? At what point does the process fail???
-
Nov 23rd, 2006, 06:41 PM
#3
Junior Member
Re: create an XML file from ASP
Here is one I use to feed a flash object with XML that I query an access database using asp and return as xml.
obviously there is a lot in here that you wont need but I'm sure you may be able to pick the bones out.
hope it helps,
Rob.
Code:
<%@LANGUAGE = VBScript%><%
DIM Cat
DIM Images
DIM Thumbs
Cat = Request.querystring("ID")
Images = "images/"
Thumbs = "thumbs/"
%><%
Dim objConn
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.open "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" & Server.MapPath("data.mdb")
DIM objRS
DIM strSQL
Set objRS = Server.CreateObject("ADODB.Recordset")
strSQL = "SELECT DISTINCT tCat.CatDesc, tSCat.SCatDesc, tSSCat.SSCatDesc, Photo.PDesc, First(Photo.PhotoID) AS FirstOfPhotoID, tCat.Secure FROM (tCat INNER JOIN tSCat ON tCat.CatID = tSCat.CatID) INNER JOIN (Photo INNER JOIN (tSSCat INNER JOIN SSC2Photo ON tSSCat.SSCatID = SSC2Photo.SSCatID) ON Photo.PhotoID = SSC2Photo.PhotoID) ON tSCat.SCatID = tSSCat.SCatID GROUP BY tCat.CatDesc, tSCat.SCatDesc, tSSCat.SSCatDesc, Photo.PDesc, tCat.Secure HAVING (((tCat.CatDesc)='" & Cat & "') AND ((tCat.Secure)='n'));"
objRS.Open strSQL, objConn, 2,3
DIM myXMLData
myXMLData = ""
myXMLData = myXMLData &"<?xml version=" & CHR(034) & "1.0" & CHR(034) & " encoding=" & CHR(034) & "UTF-8" & CHR(034) & "?>" & VBLF
myXMLData = myXMLData &"<gallery>" & VBLF
%>
<%
Do While Not objRS.EOF
DIM PhotoIDVal
DIM SSCatDescVal
PhotoIDVal = (objRS.Fields("FirstOfPhotoID").value)
SSCatDescVal = (objRS.Fields("SSCatDesc").value)
DIM oRS_O
DIM oRS_C
DIM oRS_F
oRS_O = "oRS_" & PhotoIDVal
oRS_C = "oRS_" & PhotoIDVal & "_count"
oRS_F = "oRS_" & PhotoIDVal & "_first"
DIM strSQL_O
DIM strSQL_C
DIM strSQL_F
strSQL_O = "strSQL_O" & PhotoIDVal
strSQL_C = "strSQL_C" & PhotoIDVal & "_count"
strSQL_F = "strSQL_F" & PhotoIDVal & "_first"
Set oRS_O = Server.CreateObject("ADODB.Recordset")
Set oRS_C = Server.CreateObject("ADODB.Recordset")
Set oRS_F = Server.CreateObject("ADODB.Recordset")
strSQL_O ="SELECT tCat.CatDesc, tSCat.SCatDesc, tSSCat.SSCatDesc, Photo.PhotoID, Photo.Filename, Photo.PDesc, tCat.Secure FROM (tCat INNER JOIN tSCat ON tCat.CatID = tSCat.CatID) INNER JOIN (Photo INNER JOIN (tSSCat INNER JOIN SSC2Photo ON tSSCat.SSCatID = SSC2Photo.SSCatID) ON Photo.PhotoID = SSC2Photo.PhotoID) ON tSCat.SCatID = tSSCat.SCatID GROUP BY tCat.CatDesc, tSCat.SCatDesc, tSSCat.SSCatDesc, Photo.PhotoID, Photo.Filename, Photo.PDesc, tCat.Secure HAVING (((tCat.CatDesc)='" & Cat & "') AND ((tSSCat.SSCatDesc)='" & SSCatDescVal & "') AND ((tCat.Secure)='n'));"
strSQL_C ="SELECT tCat.CatDesc, tSCat.SCatDesc, tSSCat.SSCatDesc, Count(Photo.Filename) AS CountOfFilename, Photo.PDesc, tCat.Secure FROM (tCat INNER JOIN tSCat ON tCat.CatID = tSCat.CatID) INNER JOIN (Photo INNER JOIN (tSSCat INNER JOIN SSC2Photo ON tSSCat.SSCatID = SSC2Photo.SSCatID) ON Photo.PhotoID = SSC2Photo.PhotoID) ON tSCat.SCatID = tSSCat.SCatID GROUP BY tCat.CatDesc, tSCat.SCatDesc, tSSCat.SSCatDesc, Photo.PDesc, tCat.Secure HAVING (((tCat.CatDesc)='" & Cat & "') AND ((tSSCat.SSCatDesc)='" & SSCatDescVal & "') AND ((tCat.Secure)='n'));"
strSQL_F ="SELECT tCat.CatDesc, tSCat.SCatDesc, tSSCat.SSCatDesc, Last(Photo.Filename) AS LastOfFilename, tCat.Secure FROM (tCat INNER JOIN tSCat ON tCat.CatID = tSCat.CatID) INNER JOIN (Photo INNER JOIN (tSSCat INNER JOIN SSC2Photo ON tSSCat.SSCatID = SSC2Photo.SSCatID) ON Photo.PhotoID = SSC2Photo.PhotoID) ON tSCat.SCatID = tSSCat.SCatID GROUP BY tCat.CatDesc, tSCat.SCatDesc, tSSCat.SSCatDesc, tCat.Secure HAVING (((tCat.CatDesc)='" & Cat & "') AND ((tSSCat.SSCatDesc)='" & SSCatDescVal & "') AND ((tCat.Secure)='n'));"
oRS_O.Open strSQL_O, objConn, 2, 3
oRS_C.Open strSQL_C, objConn, 2, 3
oRS_F.Open strSQL_F, objConn, 2, 3
myXMLData = myXMLData & "<album title=" & Chr(34) & oRS_O("SSCatDesc") & Chr(34) & " lgPath=" & Chr(34) & Images & Chr(34) & " tnPath=" & Chr(34) & Thumbs & Chr(34) & " tn=" & Chr(34) & Thumbs & oRS_F("LastOfFilename") & Chr(34) & " description=" & Chr(34) & oRS_C("CountOfFilename") & " images" & Chr(34) & ">" & vbLf
Do While Not oRS_O.EOF
myXMLData = myXMLData & "<img src=" & Chr(34) & oRS_O("FileName") & Chr(34) & " />" & vbLf
oRS_O.MoveNext
Loop
myXMLData = myXMLData &"</album>" & VBLF
oRS_O.Close
oRS_C.Close
oRS_F.Close
Set oRS_O = Nothing
Set oRS_C = Nothing
Set oRS_F = Nothing
objRS.MoveNext
Loop
%>
<%
objRS.Close
objConn.Close
Set objRS = Nothing
Set objConn = Nothing
myXMLData = myXMLData &"</gallery>"
Response.Write myXMLData
%>
-
Nov 26th, 2006, 10:33 AM
#4
Addicted Member
Re: create an XML file from ASP
 Originally Posted by robm_01
Here is one I use to feed a flash object with XML that I query an access database using asp and return as xml.
obviously there is a lot in here that you wont need but I'm sure you may be able to pick the bones out.
hope it helps,
Rob.
Code:
<%@LANGUAGE = VBScript%><%
DIM Cat
DIM Images
DIM Thumbs
Cat = Request.querystring("ID")
Images = "images/"
Thumbs = "thumbs/"
%><%
Dim objConn
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.open "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" & Server.MapPath("data.mdb")
DIM objRS
DIM strSQL
Set objRS = Server.CreateObject("ADODB.Recordset")
strSQL = "SELECT DISTINCT tCat.CatDesc, tSCat.SCatDesc, tSSCat.SSCatDesc, Photo.PDesc, First(Photo.PhotoID) AS FirstOfPhotoID, tCat.Secure FROM (tCat INNER JOIN tSCat ON tCat.CatID = tSCat.CatID) INNER JOIN (Photo INNER JOIN (tSSCat INNER JOIN SSC2Photo ON tSSCat.SSCatID = SSC2Photo.SSCatID) ON Photo.PhotoID = SSC2Photo.PhotoID) ON tSCat.SCatID = tSSCat.SCatID GROUP BY tCat.CatDesc, tSCat.SCatDesc, tSSCat.SSCatDesc, Photo.PDesc, tCat.Secure HAVING (((tCat.CatDesc)='" & Cat & "') AND ((tCat.Secure)='n'));"
objRS.Open strSQL, objConn, 2,3
DIM myXMLData
myXMLData = ""
myXMLData = myXMLData &"<?xml version=" & CHR(034) & "1.0" & CHR(034) & " encoding=" & CHR(034) & "UTF-8" & CHR(034) & "?>" & VBLF
myXMLData = myXMLData &"<gallery>" & VBLF
%>
<%
Do While Not objRS.EOF
DIM PhotoIDVal
DIM SSCatDescVal
PhotoIDVal = (objRS.Fields("FirstOfPhotoID").value)
SSCatDescVal = (objRS.Fields("SSCatDesc").value)
DIM oRS_O
DIM oRS_C
DIM oRS_F
oRS_O = "oRS_" & PhotoIDVal
oRS_C = "oRS_" & PhotoIDVal & "_count"
oRS_F = "oRS_" & PhotoIDVal & "_first"
DIM strSQL_O
DIM strSQL_C
DIM strSQL_F
strSQL_O = "strSQL_O" & PhotoIDVal
strSQL_C = "strSQL_C" & PhotoIDVal & "_count"
strSQL_F = "strSQL_F" & PhotoIDVal & "_first"
Set oRS_O = Server.CreateObject("ADODB.Recordset")
Set oRS_C = Server.CreateObject("ADODB.Recordset")
Set oRS_F = Server.CreateObject("ADODB.Recordset")
strSQL_O ="SELECT tCat.CatDesc, tSCat.SCatDesc, tSSCat.SSCatDesc, Photo.PhotoID, Photo.Filename, Photo.PDesc, tCat.Secure FROM (tCat INNER JOIN tSCat ON tCat.CatID = tSCat.CatID) INNER JOIN (Photo INNER JOIN (tSSCat INNER JOIN SSC2Photo ON tSSCat.SSCatID = SSC2Photo.SSCatID) ON Photo.PhotoID = SSC2Photo.PhotoID) ON tSCat.SCatID = tSSCat.SCatID GROUP BY tCat.CatDesc, tSCat.SCatDesc, tSSCat.SSCatDesc, Photo.PhotoID, Photo.Filename, Photo.PDesc, tCat.Secure HAVING (((tCat.CatDesc)='" & Cat & "') AND ((tSSCat.SSCatDesc)='" & SSCatDescVal & "') AND ((tCat.Secure)='n'));"
strSQL_C ="SELECT tCat.CatDesc, tSCat.SCatDesc, tSSCat.SSCatDesc, Count(Photo.Filename) AS CountOfFilename, Photo.PDesc, tCat.Secure FROM (tCat INNER JOIN tSCat ON tCat.CatID = tSCat.CatID) INNER JOIN (Photo INNER JOIN (tSSCat INNER JOIN SSC2Photo ON tSSCat.SSCatID = SSC2Photo.SSCatID) ON Photo.PhotoID = SSC2Photo.PhotoID) ON tSCat.SCatID = tSSCat.SCatID GROUP BY tCat.CatDesc, tSCat.SCatDesc, tSSCat.SSCatDesc, Photo.PDesc, tCat.Secure HAVING (((tCat.CatDesc)='" & Cat & "') AND ((tSSCat.SSCatDesc)='" & SSCatDescVal & "') AND ((tCat.Secure)='n'));"
strSQL_F ="SELECT tCat.CatDesc, tSCat.SCatDesc, tSSCat.SSCatDesc, Last(Photo.Filename) AS LastOfFilename, tCat.Secure FROM (tCat INNER JOIN tSCat ON tCat.CatID = tSCat.CatID) INNER JOIN (Photo INNER JOIN (tSSCat INNER JOIN SSC2Photo ON tSSCat.SSCatID = SSC2Photo.SSCatID) ON Photo.PhotoID = SSC2Photo.PhotoID) ON tSCat.SCatID = tSSCat.SCatID GROUP BY tCat.CatDesc, tSCat.SCatDesc, tSSCat.SSCatDesc, tCat.Secure HAVING (((tCat.CatDesc)='" & Cat & "') AND ((tSSCat.SSCatDesc)='" & SSCatDescVal & "') AND ((tCat.Secure)='n'));"
oRS_O.Open strSQL_O, objConn, 2, 3
oRS_C.Open strSQL_C, objConn, 2, 3
oRS_F.Open strSQL_F, objConn, 2, 3
myXMLData = myXMLData & "<album title=" & Chr(34) & oRS_O("SSCatDesc") & Chr(34) & " lgPath=" & Chr(34) & Images & Chr(34) & " tnPath=" & Chr(34) & Thumbs & Chr(34) & " tn=" & Chr(34) & Thumbs & oRS_F("LastOfFilename") & Chr(34) & " description=" & Chr(34) & oRS_C("CountOfFilename") & " images" & Chr(34) & ">" & vbLf
Do While Not oRS_O.EOF
myXMLData = myXMLData & "<img src=" & Chr(34) & oRS_O("FileName") & Chr(34) & " />" & vbLf
oRS_O.MoveNext
Loop
myXMLData = myXMLData &"</album>" & VBLF
oRS_O.Close
oRS_C.Close
oRS_F.Close
Set oRS_O = Nothing
Set oRS_C = Nothing
Set oRS_F = Nothing
objRS.MoveNext
Loop
%>
<%
objRS.Close
objConn.Close
Set objRS = Nothing
Set objConn = Nothing
myXMLData = myXMLData &"</gallery>"
Response.Write myXMLData
%>
Ok - but what is the problem... what error are you getting? Which line is the error on? What is the result of this code? Nothing? an error? mal-formed xml? what?
-
Nov 27th, 2006, 03:56 AM
#5
Thread Starter
Lively Member
Re: create an XML file from ASP
never mind all fixed thanks.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|