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.dt d">
<script runat="server">
Sub btnWriteXML_OnC lick(ByVal sender As Object, ByVal e As
EventArgs)
Try
Dim enc As Encoding
Dim objXMLTW As New
HtmlTextWriter( Server.MapPath( "menu.xml") , enc)
objXMLTW.WriteS tartDocument()
objXMLTW.WriteS tartElement("Na me")
objXMLTW.WriteS tring(Request(" txtName"))
objXMLTW.WriteE ndElement()
objXMLTW.WriteE ndDocument()
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>Untitl ed 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.comwrote :
On Jun 8, 5:42 pm, slinky <campbellbrian2 ...@yahoo.comwr ote:
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_Clic k(ByVal sender As System.Object, ByVal
e As System.EventArg s) Handles btnLoadXml.Clic k
Dim xtr As XmlTextReader = _
New XmlTextReader(" C:\Documents and Settings\dcampb e\My
Documents\Visua l Studio 2005\Projects\3 10C02\310C02\Bo oks.xml")
xdd = New XmlDataDocument ()
ds = xdd.DataSet()
ds.ReadXmlSchem a(xtr)
xtr.Close()
xtr = New XmlTextReader(" C:\Documents and Settings\dcampb e\My
Documents\Visua l Studio 2005\Projects\3 10C02\310C02\Bo oks.xml")
xtr.WhitespaceH andling = WhitespaceHandl ing.None
xdd.Load(xtr)
dgXML.DataSourc e = ds
dgXML.DataMembe r = "Book"
xtr.Close()
End Sub
Private Sub btnSave_Click(B yVal sender As System.Object, ByVal e
As System.EventArg s) Handles btnSave.Click
Dim xtw As XmlTextWriter = New XmlTextWriter(" C:\Documents and
Settings\dcampb e\My Documents\Visua l Studio 2005\Projects
\310C02\310C02\ Books.xml", System.Text.Enc oding.UTF8)
xtw.Formatting = Formatting.Inde nted
xdd.WriteTo(xtw )
'Clean up
xtw.Close()
MessageBox.Show ("The XML file has been successfully
updated !")
End Sub
End Class