Reply to topic
Creating an XML file on the server
Ennio


Joined: 17 Nov 2006
Posts: 98
Location: Scotch Plains, NJ
Reply with quote
Is it possible to create an XML file with the information the user gives me, and save on the server?
Jason101
Forum Regular

Joined: 14 Mar 2006
Posts: 548
Location: Harrisburg, PA
Reply with quote
Sure Can..

It can be a query, form content, or anything at all..

Code:

<!--- Save XML content to variable --->
<cfsavecontent variable="XML_Content">
    <?xml version="1.0" encoding="UTF-8" ?>
       <userid>#User.UserID#</userid>
       <username>#User.UserName#</username>
          .......
</cfsavecontent>

<!--- Write to disk --->
<cffile file="D:\Websites\www\Dir\UserXML.xml" output="#XML_Content#">


If you are unfamiliar with cffile, here's the quickdocs
http://www.cfquickdocs.com/?getDoc=cffile
Ennio


Joined: 17 Nov 2006
Posts: 98
Location: Scotch Plains, NJ
Reply with quote
Jason that worked... thanks

one more question... now if I need to open the xml and make some updates

here is the structure of my xml file..

Code:

- <playlist>
- <item>
  <filename>example1.mp3</filename>
  <artist>Ennio</artist>
  <album />
  <title>Test XML</title>
  </item>
  </playlist>


I need to add now another item inside the playlist.
Jason101
Forum Regular

Joined: 14 Mar 2006
Posts: 548
Location: Harrisburg, PA
Reply with quote
Just do the same thing, except add append to cffile...

Code:

<cffile file="D:\Websites\www\Dir\UserXML.xml" output="#XML_Content#" action="append">


This will open the file, and add to it.
Ennio


Joined: 17 Nov 2006
Posts: 98
Location: Scotch Plains, NJ
Reply with quote
I got an error saying I can only have one top level.

Code:

<!--- Save XML content to variable --->
<cfsavecontent variable="XML_Content">
<item>
   <filename><cfoutput>#File.ServerFile#</cfoutput></filename>
   <artist><cfoutput>#Session.bandname#</cfoutput></artist>
   <album></album>
   <title><cfoutput>#Form.txtTitle#</cfoutput></title>
   <track></track>
   <comments></comments>
   <genre></genre>
   <seconds></seconds>
   <filesize></filesize>
   <bitrate></bitrate>
   <visual></visual>
   <url></url>
</item>
</cfsavecontent>
<!--- Write to disk --->
<cffile action="append" file="C:\websites\108817ut4artist\#Session.bandname#\music\playlist.xml" output="#XML_Content#">


I removed the <playlist> this is my top level and still get the error
Jason101
Forum Regular

Joined: 14 Mar 2006
Posts: 548
Location: Harrisburg, PA
Reply with quote
Hmm.. You shouldn't get that kind of error unless you are specifically parsing the XML file. For all Coldfusion is concerned, you are just writing to a file. It doesn't care what you put in there.

Do you have a page where I can see the error? If not, can you post a screenshot and we'll go from there.
pmeserve
HostMySite Tech

Joined: 19 Mar 2004
Posts: 178
Reply with quote
Ennio - Is this file meant to be parsed by anything other than your script? If not, I'd highly recommend using a database to store data rather than XML - it would likely save you a lot of headaches
Jason101
Forum Regular

Joined: 14 Mar 2006
Posts: 548
Location: Harrisburg, PA
Reply with quote
pmeserve wrote:
Ennio - Is this file meant to be parsed by anything other than your script? If not, I'd highly recommend using a database to store data rather than XML - it would likely save you a lot of headaches


I would agree with that. If you have an app that needs to read an xml file, you can just pull the data from the database and create on one the fly like you're doing above.
Ennio


Joined: 17 Nov 2006
Posts: 98
Location: Scotch Plains, NJ
Reply with quote
Hi guys,...thanks for the advice... I did change to a DB

I was developing a flash mp3 player using xml, but I'm going to use a db.
Creating an XML file on the server
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
All times are GMT  
Page 1 of 1  

  
  
 Reply to topic