Click to See Complete Forum and Search --> : Creating XML from HTML Form
I am looking for a simple way to take a simple HTML form and create an XML document from the data in the form. So far, I have found many "tutorials" online for ASP and PHP on how to do this, but have yet to get any of them to work correctly. If anyone has any suggestions about this, I would greatly appreciate it!
jkmyoung
06-07-2007, 02:47 PM
XForms were designed to do just that. However, support for it is limited to Mozilla. However, there are applications designed to convert xforms into cross-browser javascript, or extra applications downloadable by the client to get it to work with IE.
If you could post sample code of a simple form you're trying to get to work, we may be able to point out where the mistakes are.
Form Code:
<html>
<head><title>New User Information</title></head>
<body>
<form action="ProcessData.asp" method="post" enctype="application/x-www-form-urlencoded">
<h2>Please provide the following information</h2>
<input type="hidden" name="func_name" value="ADD_USER">
<table>
<tr><td><b>First Name:</b></td>
<td><input type="text" name="firstname" size="40"></td></tr>
<tr><td><b>Middle Name:</b></td>
<td><input type="text" name="middlename" size="40"></td></tr>
<tr><td><b>Last Name:</b></td>
<td><input type="text" name="lastname" size="40"></td></tr>
<tr><td><b>Street Address:</b></td>
<td><input type="text" name="address" size="40"></td></tr>
<tr><td><b>City, State - Zip:</b></td>
<td><input type="text" name="city" size="30">,
<input type="text" name="state" size="2">
<input type="text" name="zip" size="10"></td></tr>
<tr><td colspan="2">
<input type="submit" name="__exclude__Submit" value="Submit">
</td></tr>
</table>
</form>
</body></html>
ASP Code:
<%
Option Explicit
'-------------------- ProcessData.asp---------------------------------
'--------------------------------------------------------------------
' The Function saveXMLData saves the XML doc in the filename specified.
' The function can be easily adapted to send the data directly to
' a database object
'--------------------------------------------------------------------
Function saveXMLData(strPath, strFileName)
'Declare local variables.
Dim aXMLDoc
Dim aRootNode
Dim aFormVar
Dim aPI
Dim Item
'Create an XMLDOM Object
Set aXMLDoc = server.CreateObject("Microsoft.XMLDOM")
aXMLDoc.preserveWhiteSpace = True
'Create the root node for the document
Set aRootNode = aXMLDoc.createElement("function")
aXMLDoc.appendChild aRootNode
'Iterate the Request Object for all form data
For Each item in Request.Form
'Do not include the variable if it contains __exclude__
If instr(1,item,"__exclude__") = 0 Then
Set aFormVar =aXMLDoc.createElement(item)
aFormVar.Text = Request.Form(item)
aRootNode.appendChild aFormVar
End If
Next
'Append the processing instruction
Set aPI = aXMLDoc.createProcessingInstruction("xml","version='1.0'")
aXMLDoc.insertBefore aPI, aXMLDoc.childNodes(0)
'Save the XML document.
aXMLDoc.save strPath & "\" & strFileName
'Release all references.
Set aXMLDoc = Nothing
Set aRootNode = Nothing
Set aFormVar= Nothing
Set item = Nothing
Set aPI = Nothing
End Function
' The page starts here
On Error Resume Next
' Save the XML Data
SaveXMLData "c:/,"NewUser.xml"
If err.number <> 0 then
Response.write("Errors occurred while saving your information."+ Err.Description)
Else
Response.write("Thank you for submitting your information.")
End If
%>
Yes, I have found many, many references to XForms. However, since 99.99% of the people that will be accessing my form use IE exclusively, I pretty much dismissed it as an option. I do not have the option of making them use Mozilla or download applications. I pretty much need something they can open in their browser and run with.