Sample Application: XML Form Generator, Part 2: Capturing User Input
page 1 of 1
Published: 29 Sep 2004
Unedited - Community Contributed
Abstract
Part 1 of this series demonstrated how to create an XML form using a DataGrid in a web page. The focus of this part is the display of the XML form using XSL to transform it and then saving the user input to an XML file.
by Andrew Mooney
Feedback
Average Rating: 
Views (Total / Last 10 Days): 12111/ 23

[ Download Code] | [ Run Sample ]
Part 1 of this series demonstrated how to create an XML form using a DataGrid in a web page. The focus of this part is the display of the XML form using XSL to transform it; and then saving the user input to an XML file.

You can actually use one web page to display all of your XML forms. In the Page_Init event, the XML form is loaded, tansformed, and added to the web page. The sample web page, that's included in the download, gets the name of the XML form from the Querystring without the extension (.xml). If there is no form in the Querystring, the sample.xml form is loaded. The XML forms are loaded from the "forms" sub-directory after adding the extension (.xml). The download contains two forms, sample.xml and test.xml.

The XSL file (forms.xsl) transforms the XML form into ASP.NET controls based on the control type. If the control contains list items, then the comma-separated string is split and transformed into ListItems. If the field in the XML form has required setting to "Yes," then a RequiredFieldValidator is added, and if the XML form field "Data" is set to Currency, Date, Double, Integer, or String then a DataTypeCheck CompareValidator is also added.

The Page_Load IsPostBack event will be triggered when the form is submitted. Here the XML form is loaded into a DataSet. The rows of the DataSet are then iterated through to get the form data based on the type of control. A new DataSet is used to hold the form data, which is then saved to the "results" sub-directory named with a GUID and the .xml extension (GUID.xml).

You'll notice that the XML form name is added to the first entry in the results file. This will allow you to save all your results in the same directory and still be able to easily determine the XML form where they originated. Using the GUID for the name is an easy way to prevent overwriting existing result files.

Now, we have a fully working application for building (Part 1) XML forms and using them to capture user input (Part2). The next step is to build a web form for viewing the results. We'll accomplish this in Part 3 of this series.



User Comments

No comments posted yet.






Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2024 ASPAlliance.com  |  Page Processed at 2024-03-28 10:12:45 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search