XML and HTML-forms example
I created this little example after I got some questions from people. I posted a message on XML.com on how to use HTML forms in XML. I was assigned a project that had to be able to read an XML document and display it in HTML in two ways:
First, just writing out the data in the file,
Second, presenting the data in the file in an HTML form so people can change it.
Finally, the changes had to be saved to a new xml file.
It turned out that there were more people trying to do this, so I think it makes sense to share this little thing with you all.
I use XSL to represent the data from the XML data into HTML. I use two different XSL sheets: one for writing out to screen as text and one for creating the form view.
These files should be in this package:
-
memo.xml
the XML file with a memo structure, such as FROM, TO, SUBJECT and MESSAGE
-
memomode.xsl
the XSL sheet that displays the memo on the screen as normal HTML
- memoeditmode.xsl
the XSL sheet that transforms the XML memo into an HTML form
-
savememo.asp
an ASP file that reads the values from the form and saves them to a filename the
user enters on the FORM page
- startexample.html
a simple page that provides links to different view modes of the XML file
-
processxml.asp
simple ASP file to render the XML file with the chosen XSL sheet.
-
help.html
this page
If you want to set this up on your own machine: I have created it so that you can place the files in the wwwroot of your webserver. You have to have the MSXML parser installed (comes with IE 5 or look at www.microsoft.com/xml and search for the redistributable). Also, for saving the files to disc on your webserver, you need to give the internet guest account in your Windows NT Domain write access for that directory, otherwise people cannot save the files, because they don't have the right permissions.