CSDN博客

img waterboy

XML Form Generator, Part 1: Generating an XML Form

发表于2004/11/3 8:26:00  1201人阅读

[ Download Code ] | [ Run Sample ]
One of the most frequent tasks that web developers receive is that of creating a form to collect user input. One solution is to use an ASP.NET web page to create an XML file that will be used as the basis for a web form. The three part article, XML Form Generator, will demonstrate how to easily create an XML form that will save user input as an XML file. By using the run sample link above you view all the source code and see an online demo.

First, we are going to need a web page that will create an XML files (XML forms) in this format:

<?xml version="1.0" standalone="yes"?>
<NewDataSet>
  <Fields>
    <Control>DropDownList</Control>
    <Data>String</Data>
    <Required>Yes</Required>
    <Order>3</Order>
    <Label>Operating System</Label>
    <Id>OS</Id>
    <Text>Windows 98,Windows XP,Other</Text>
  </Fields>
  . . . . . 
</NewDataSet>

Here is the explanation of the fields:

  • Control - The type of ASP.NET web server control
  • Data - The type of data that the form will take as input
  • Required - Is the field required
  • Order - The order that the fields will be displayed in the form
  • Label - The field label that is displayed on the form
  • Id - The ASP.NET web server control id
  • Text - This field is use in multiple ways:
    • For TextBox, Multiline, Hidden, Password and Label controls this is the default value (Note: Multiline, Hidden, Password are all TextBox controls)
    • For DropDownList, RadioButtonList and CheckBoxList and ListBox controls a comma separated list will be displayed as separate items
    • For a CheckBox control it the text displayed next to it

How to run the sample:

  1. Download and extract the files to a virtual directory.
  2. Use your web browser to navigate to the XmlFormGen.aspx file in that virtual directory.
  3. To load the included test form type in Test.xml and click the Load Form button.
  4. To create a new form type in the name of the form and add a .xml extension. Then click on the New Form button.
  5. You can now edit, delete, and add fields on you form.
That's all there is to creating a form. I know what you're thinking, all this does is create XML files. But, it actually creates a very specific kind of XML file that I am calling an XML form. The next part of this series will demonstrate how we can use these XML forms to capture user input and save the results to XML files.
阅读全文
0 0

相关文章推荐

img
取 消
img