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

generating xml from html

Status
Not open for further replies.

danfood

Programmer
Aug 8, 2001
32
GB
Does anyone know how to take the information from a form in HTML and automatically turn it into XML.
ie
in a form on a web page someone enters their details, the data is then taken and put in an XML database. This info could then be displayed elsewhere using XSL to interogate the XML data.

Cheers
Dan
 
goto - their last three articles address this, see the one on "appending an xml document"

hope that helps...

oh yeh, this uses asp - Im sure similar things can be done w/ perl or php, but I wouldnt know how...
 
You can do the same thing in ASP, with VBScript as your scripting langauge.

In the following code, I'm taking form fields and sticking their input between XML tags that I defined. The only thing is that I haven't yet added in the VBScript "CreateTextFile" method to automatically write this to a file on the server. It's definetly possible, though.

In the meantime, I just run this script and then view the source in MSIE, and then save the outputted HTML as an XML file. It's perfectly formmated for it....just not automated.

In this example, FORM.ASP is just the run-of-the-mill HTML form, but it posts to a preformatted XML format in CREATE_NEW.ASP (albeit saved as an ASP). More complex scripting to have it saved and posted as XML directly to the server.


*********************************************
FORM.ASP
*********************************************

<HTML>
<HEAD><TITLE>A sample form</TITLE></HEAD>
<BODY>

Enter your info here:<br><br>
<FORM method=&quot;post&quot; action=&quot;create_new_xml.asp&quot;>
<INPUT TYPE=&quot;text&quot; width=&quot;65&quot; name=&quot;name&quot;><br>
Enter your name above<br><br>

<INPUT TYPE=&quot;text&quot; width=&quot;65&quot; name=&quot;email&quot;><br>
Enter your email above<br><br>

<INPUT TYPE=&quot;text&quot; width=&quot;65&quot; name=&quot;address&quot;><br>
Enter your email above<br><br>

<INPUT type=&quot;submit&quot; value=&quot;Submit&quot; name=&quot;submit&quot;>
</FORM>
</BODY>
</HTML>


*********************************************
CREATE_NEW_XML.ASP
*********************************************

<% @ Language = VBScript %>

<%
' DECLARE VARIABLES AND STATE THEIR VALUES
Dim name, email, address
name = Request.Form(&quot;name&quot;)
email = Request.Form(&quot;email&quot;)
address = Request.Form(&quot;address&quot;)
%>

<?xml version=&quot;1.0&quot;?>
<CUSTOMERS>
<CLIENT>
<NAME><%=name%></NAME>
<EMAIL><%=email%></EMAIL>
<ADDRESS><%=address%></ADDRESS>
</CLIENT>
</CUSTOMERS>

*****************************

Cheers from Guam,
Jas
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top