Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

write simple xml file... 1

Status
Not open for further replies.

thompom

Technical User
Dec 4, 2006
395
GB
hi,

am stuck with doing this task - i am trying to write to disk an xml file that looks like

Code:
<newsTicker>
<item>
<header>News item 1</header>
<link newWindow="_blank"></link>
</item>
<item>
<header>News item 2</header>
<link newWindow="_blank"></link>
</item>
</newsTicker>

so far i have tried

Code:
jobssql = "SELECT jobtitle, jobid "
jobssql = jobssql & "FROM jobs"

Set rsjobs = Server.CreateObject("ADODB.Recordset")

rsjobs.Open jobssql, sconn 

Dim xml_string

'Create FSO Objects
dim objFso, xmlFile
set objFso = server.createobject("Scripting.FileSystemObject")
'create the xml file
set xmlFile = objFso.CreateTextFile("jobsxml.xml")

'start writing our xml to the file we just created.
xmlFile.Write("<xml version='1.0' ?>")

xmlFile.Write "<newsTicker>"

do while not rsjobs.eof

x_jobtitle = rsjobs("jobtitle")
'pretend invoice_id passed as txtInvoiceId
xmlFile.Write "<item><header>" & (x_jobtitle) & "</header><link newWindow=_blank></link></item>"

rsjobs.movenext
loop
rsjobs.close

xmlFile.Write "</newsTicker>"
'close file
xmlFile.Close()
'destroy FSO objects
Set objFso = Nothing

but kept getting 'permission denied error' - tried all security permission settings on IUSR_pcname account
but couldnt get it get past that error, besides this code
had to run on a 3rd party host that i cant change the permissions.

so next i tried

Code:
Set rstXML = Server.CreateObject("ADODB.Recordset")
Set rstXML = cnnXML.Execute("SELECT jobid, jobtitle FROM jobs ORDER BY jobid")

' Save the file to XML format.
rstXML.Save Server.MapPath("jobsxml.xml"), adPersistXML
[code]

but with this method you are stuck with the adPersistXML format - i think i need to use an xslt template file
any ideas welcome
 
Try configuring IIS web server to use your local admin account for the ASP.


besides this code had to run on a 3rd party host that i cant change the permissions

I think you might be out of luck if you the host doesn't give you write access.
 
thanks for your reply Sheco, i just did a test on my fasthosts space with the following code

Code:
<!--#include file="autobase/db.asp"-->
<!-- #include file="adovbs.inc" -->

<%
' Delete existing file
Dim objFSO
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists(Server.MapPath("jobsxml.xml")) Then
	objFSO.DeleteFile Server.MapPath("jobsxml.xml")
End IF
Set objFSO = Nothing

' Declare our variables... always good practice.
Dim cnnXML  ' ADO connection
Dim rstXML  ' ADO recordset

' Create an ADO Connection to connect to the scratch database.
' We're using OLE DB but you could just as easily use ODBC or a DSN.
Set cnnXML = Server.CreateObject("ADODB.Connection")
cnnXML.Open xDb_Conn_Str
Set rstXML = Server.CreateObject("ADODB.Recordset")
Set rstXML = cnnXML.Execute("SELECT jobid, jobtitle FROM jobs ORDER BY jobid")

' Save the file to XML format.
rstXML.Save Server.MapPath("jobsxml.xml"), adPersistXML

rstXML.Close
Set rstXML = Nothing
cnnXML.Close
Set cnnXML = Nothing
%>

and an xml file was written - phew!, but the output looks like

Code:
- <xml xmlns:s="uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882" xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882" xmlns:rs="urn:schemas-microsoft-com:rowset" xmlns:z="#RowsetSchema">
- <s:Schema id="RowsetSchema">
- <s:ElementType name="row" content="eltOnly" rs:CommandTimeout="30">
- <s:AttributeType name="jobid" rs:number="1" rs:nullable="true" rs:writeunknown="true">
  <s:datatype dt:type="int" dt:maxLength="4" rs:precision="11" rs:fixedlength="true" /> 
  </s:AttributeType>
- <s:AttributeType name="jobtitle" rs:number="2" rs:nullable="true" rs:writeunknown="true">
  <s:datatype dt:type="string" rs:dbtype="str" dt:maxLength="100" /> 
  </s:AttributeType>
  <s:extends type="rs:rowbase" /> 
  </s:ElementType>
  </s:Schema>
- <rs:data>
  <z:row jobid="1" jobtitle="Valeter" /> 
  <z:row jobid="2" jobtitle="Workshop Controller" /> 
  <z:row jobid="6" jobtitle="Sales Executives" /> 
  <z:row jobid="10" jobtitle="MOT Tester" /> 
  <z:row jobid="11" jobtitle="Trainee Business Manager" /> 
  </rs:data>
  </xml>

now, i know what format i need, so now i need to know how to customise that content
 
Did you try making a simple ASP just to test the write capability? Something like the second code example in this FAQ: faq333-504
 
Modify it to write your XML string instead of "Hello world"
 
hi - thanks again sheco, job done - seems like i was over complicating this [should remember KISS]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top