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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Taking Web form and saving info to XML 2

Status
Not open for further replies.

artguy

Technical User
Feb 2, 2001
117
US
I'm trying to figure out the easiest way to write to an XML file using ASP(vbscript) from a simple HTML form.

I already have existing pages that grab the data from existing XML documents so I thought I could figure out the best way to write to them.

I've run across ASP tutorials and ASP.net tutorials all with different methods. I'm trying to find the easiest method to use for a person with limited XML exposure and a novice with ASP. Any suggestions to what I should be looking for?
 
The easiest way, if you don't care about the exact schema, might be to persist an ADO recordset to disk.
 
Well, it would be nice to get it into a format similar to this:
Code:
 <news>
    <article id="">
	 <date></date>
	 <headline></headline>
	 <story></story>
    </article>
 </news>
If possible.
 
Since I have particular needs as far as this particular format and I don't have access to a database, what kind of ASP tutorial should I be searching for? Trying to avoid anything that may be deprecated by now.

Main goal is to be able to create/edit XML file(s) using ASP and HTML forms with the above XML setup. Any particular search terms to Google or sites would be greatly appreciated.

Thanks for your time.
 
Oh... you've got a <form> and you want to save the submitted values into an xml file?

If it is a short little file you might as well just make a string and write it to disk with the FileSystemObject.

If it is longer then perhaps create template xml file and load that up into the parser... something like this:
Set oXML = CreateObject("Msxml2.DOMDocument.4.0")
oXML.load("MyTemplate.xml")

Assuming your <form> elements share the same name as the values in your xml file then you can iterate through the nodelist and fetch its value from the Request collection.

 
The parsing part was easy and i have that setup to display the contents of my XML files. It was just the figuring out how to add another article into my news root within the XML file or edit existing entries within the file that has me perplexed.

Would I just load the existing contents of the file into an object and then edit the contents with a form and rewrite the whole file again once I'm finished editing by using the FileSystemObject?
 
artguy,

It's easiest when you've got an existing XML document to parse using the MSXML parser and add nodes with the inbuilt methods.

e.g.:

Otherwise it is normally easiest to do it through string concatenation and the filesystemobject - but if you've got a lot of rows to append, you should look into a fast string concatenation method -otherwise it will eat up processor time.

Hope that helps.

A smile is worth a thousand kind words. So smile, it's easy! :)
 
I had run across that page before but was unsure at first glance if it was OK to do it that way. On second glance, I will definitely give it a try.

Thank you, damber, and you, Scheco, for your sage advice and for your time responding.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top