I went to the site you listed for Writing to XML... I have put
together a form with a textbox and a button... my code is below... I
simply want a user to add a record to the XML file then hit the submit
button, but I can seem to get the plumbing right on this one. I get
several errors. I've been able to do not unsimilar things with XML for
desktop apps (see my code at very bottom) but ASP is really throwing
me! Thanks for any help... struggling still....
<%@ Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Sub btnWriteXML_OnClick(ByVal sender As Object, ByVal e As
EventArgs)
Try
Dim enc As Encoding
Dim objXMLTW As New
HtmlTextWriter(Server.MapPath("menu.xml"), enc)
objXMLTW.WriteStartDocument()
objXMLTW.WriteStartElement("Name")
objXMLTW.WriteString(Request("txtName"))
objXMLTW.WriteEndElement()
objXMLTW.WriteEndDocument()
objXMLTW.Flush()
objXMLTW.Close()
Catch Ex As Exception
Dim MessageBox As MsgBoxResult
MessageBox = "The following error occurred: " & Ex.Message
End Try
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head2" runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="btnWriteXML" runat="server" Text="Button" />
<asp:TextBox ID="txtName" runat="server"></asp:TextBox></div>
</form>
</body>
</html>
On Jun 8, 3:14 pm, Alexey Smirnov <alexey.smir...@gmail.com> wrote:
> On Jun 8, 5:42 pm, slinky <campbellbrian2...@yahoo.com> wrote:
>
> > That makes sense...... also along the lines of XML editing, etc. If I
> > had an .aspx form that I wanted to simply have three textboxes
> > (corresponding to Author, Title, and Year as in your XML file), and a
> > submit button... how could I setup the code/form so the user could
> > enter a book and hit Submit and add that to the XML file? I don't want
> > the list of books to be displayed though on this form. I've done this
> > before in vb.net with an XML file for a desktop app, but not for
> > an .aspx app. Any clues? Thanks!
>
> There are tons of articles and examples about that subject on the web
>
> For example:http://www.freevbcode.com/ShowCode.asp?ID=2789
__________________________________________________ ________________
Imports System.Data
Imports System.Xml
Public Class StepByStep2_4
Dim xdd As XmlDataDocument
Dim ds As DataSet
Private Sub btnLoadXml_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles btnLoadXml.Click
Dim xtr As XmlTextReader = _
New XmlTextReader("C:\Documents and Settings\dcampbe\My
Documents\Visual Studio 2005\Projects\310C02\310C02\Books.xml")
xdd = New XmlDataDocument()
ds = xdd.DataSet()
ds.ReadXmlSchema(xtr)
xtr.Close()
xtr = New XmlTextReader("C:\Documents and Settings\dcampbe\My
Documents\Visual Studio 2005\Projects\310C02\310C02\Books.xml")
xtr.WhitespaceHandling = WhitespaceHandling.None
xdd.Load(xtr)
dgXML.DataSource = ds
dgXML.DataMember = "Book"
xtr.Close()
End Sub
Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles btnSave.Click
Dim xtw As XmlTextWriter = New XmlTextWriter("C:\Documents and
Settings\dcampbe\My Documents\Visual Studio 2005\Projects
\310C02\310C02\Books.xml", System.Text.Encoding.UTF

xtw.Formatting = Formatting.Indented
xdd.WriteTo(xtw)
'Clean up
xtw.Close()
MessageBox.Show("The XML file has been successfully
updated !")
End Sub
End Class