thanks for your reply I have sort of got it working using the following code but my issue is that i need to create a new xml file everytime. (the code I am working with replaces the information in the xml file) I thought i could do this by adding a timestamp to the filename code but i am not sure how to do this.
it is a aspx page with code behind vb
this is the .aspx file
<%@ Page Language="vb" Src="WebFormToXml.aspx.vb" Inherits="WebFormToXml" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>WebFormToXml</title>
<meta name="GENERATOR" content="Microsoft Visual Studio.NET 7.0">
<meta name="CODE_LANGUAGE" content="Visual Basic 7.0">
<meta name=vs_defaultClientScript content="JavaScript">
<meta name=vs_targetSchema content="http://schemas.microsoft.com/intellisense/ie5">
</head>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<table border="1" cellspacing="0" cellpadding="4">
<tr>
<td bgcolor="EEEEEE" align="right">Last Name:</td>
<td align="left"><asp:TextBox id="txtLastName" runat="server" /></td>
<tr>
<td bgcolor="EEEEEE" align="right">First Name:</td>
<td align="left"><asp:TextBox id="txtFirstName" runat="server" /></td>
</tr>
<tr>
<td bgcolor="EEEEEE" align="right">Middle Name:</td>
<td align="left"><asp:TextBox id="txtMiddleName" runat="server" /></td>
</tr>
<tr>
<td bgcolor="EEEEEE" align="right">Address:</td>
<td align="left"><asp:TextBox id="txtAddress" runat="server" /></td>
</tr>
<tr>
<td bgcolor="EEEEEE" align="right">City:</td>
<td align="left"><asp:TextBox id="txtCity" runat="server" /></td>
</tr>
<tr>
<td bgcolor="EEEEEE" align="right">State:</td>
<td align="left"><asp:TextBox id="txtState" runat="server" /></td>
</tr>
<tr>
<td bgcolor="EEEEEE" align="right">Zip Code:</td>
<td align="left"><asp:TextBox id="txtZipCode" runat="server" /></td>
</tr>
<tr>
<td align="center" colspan="2">
<asp:Button id="btnWriteXml" OnClick="Write_XML" Text="Write XML File" runat="server" />
</td>
</tr>
</table>
</form>
</body>
</html>
and this is the VB
mports System.Xml
Imports System.Web.UI.WebControls
Public Class WebFormToXml : Inherits System.Web.UI.Page
Protected txtLastName As TextBox
Protected txtFirstName As TextBox
Protected txtMiddleName As TextBox
Protected txtAddress As TextBox
Protected txtCity As TextBox
Protected txtState As TextBox
Protected filestamp As Datetime
Protected txtZipCode As TextBox
Public Sub Write_XML(ByVal sender As System.Object, ByVal e As System.EventArgs)
Dim textWriter As New XmlTextWriter(Server.MapPath("PersonData.xml"), Nothing)
textWriter.Formatting = System.Xml.Formatting.Indented
'Start New Document
textWriter.WriteStartDocument()
'Write a Comment
textWriter.WriteComment("This is a comment")
'Insert Start Element
textWriter.WriteStartElement("PersonalData")
'Write Attribute for Start Element
textWriter.WriteAttributeString("DataType", "NameAndAddress")
'Write LastName Element and Data
textWriter.WriteStartElement("LastName", "")
textWriter.WriteString(txtLastName.Text)
textWriter.WriteEndElement()
'Write FirstName Element and Data
textWriter.WriteStartElement("FirstName", "")
textWriter.WriteString(txtFirstName.Text)
textWriter.WriteEndElement()
'Write MiddleName Element and Data
textWriter.WriteStartElement("MiddleName", "")
textWriter.WriteString(txtMiddleName.Text)
textWriter.WriteEndElement()
'Write Address Element and Data
textWriter.WriteStartElement("Address", "")
textWriter.WriteString(txtAddress.Text)
textWriter.WriteEndElement()
'Write City Element and Data
textWriter.WriteStartElement("City", "")
textWriter.WriteString(txtCity.Text)
textWriter.WriteEndElement()
'Write State Element and Data
textWriter.WriteStartElement("State", "")
textWriter.WriteString(txtState.Text)
textWriter.WriteEndElement()
'Write ZipCode Elment and Data
textWriter.WriteStartElement("ZipCode", "")
textWriter.WriteString(txtZipCode.Text)
textWriter.WriteEndElement()
'End Everything
textWriter.WriteEndDocument()
'Clean up
textWriter.Flush()
textWriter.Close()
'Display the XML Document
Response.Redirect(Server.MapPath("PersonData.xml"))
End Sub
End Class
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125:





by: VelioPosted on 2008-07-02 at 03:51:19ID: 21915011
Hi,
You could either have code which manually creates the xml based on the user input from the various controls you place on the form, or wrap it all in a object which you can serialize using XmlSerializer.
If you could provide some more details... otherwise it could be as simple as something like this:
Select allOpen in new window