473,657 Members | 2,716 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

updating with aspx and XML file

Thanks in advance fo rany help... I have an XML data file (well-
formed) that I need to place into my website's app_data folder. I
would like to have an .aspx form on my site that simply has two
textboxes (corresponding to two XML fields in my file), and a
"submit"
button that will update the file. Any clues as to the code to use?

I'm most familiar with the DataAdapter/DataSet model and using
SQLserver files and having an INSERT INTO query to update. Can this
be
used on an XML file also? There may be better ways, but just curious
if this model COULD work with XML.
Thanks!

Jun 5 '07 #1
15 2480
On Jun 5, 9:31 pm, slinky <campbellbrian2 ...@yahoo.comwr ote:
Thanks in advance fo rany help... I have an XML data file (well-
formed) that I need to place into my website's app_data folder. I
would like to have an .aspx form on my site that simply has two
textboxes (corresponding to two XML fields in my file), and a
"submit"
button that will update the file. Any clues as to the code to use?

I'm most familiar with the DataAdapter/DataSet model and using
SQLserver files and having an INSERT INTO query to update. Can this
be
used on an XML file also? There may be better ways, but just curious
if this model COULD work with XML.
Thanks!
Dim myDataSet as New DataSet()
myDataSet.ReadX ml(Server.MapPa th("books.xml") )

http://aspnet.4guysfromrolla.com/articles/052902-1.aspx

http://www.google.com/search?hl=en&q...et+xml+asp.net

Jun 5 '07 #2
Thanks! http://aspnet.4guysfromrolla.com/articles/052902-1.aspx is a
great site...but I tried out some of you code below from the site (I'm
a student-newbie using Visual Web Developer Express 2005). I pasted
the following into a blank .aspx page and your books.xml file into my
app_data folder on my site, re-build, and get rid of some errors, I
try to view it in my browser and I get server errors:

here's my aspx:

<%@ import Namespace="Syst em.Data" %>
<script runat="server">
sub Page_Load(sende r as Object, e as EventArgs)
Dim myDataSet as New DataSet()

myDataSet.ReadX ml(Server.MapPa th("books.xml") )

dgBooks.DataSou rce = myDataSet
dgBooks.DataBin d()

dgBooksPretty.D ataSource = myDataSet
dgBooksPretty.D ataBind()
end sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>StartPag e</title>
</head>
<body>
<b>The Contents of the XML File
<a href="/demos/books.xml"><cod e>books.xml</code></a></b><br />
<asp:datagrid id="dgBooks" runat="server" />

<p align="center">
<b>A Nicer Looking DataGrid Representation of the XML File
<a href="/demos/books.xml"><cod e>books.xml</code></a></b><br />
</p>
<asp:datagrid id="dgBooksPret ty" runat="server"
AutoGenerateCol umns="False"
Font-Name="Verdana"
Font-Size="Small"
HorizontalAlign ="Center"
ItemStyle-BackColor="#FFF FCC"
AlternatingItem Style-BackColor="#EEE EEE">

<HeaderStyle BackColor="Red" HorizontalAlign ="Center"
ForeColor="Whit e" Font-Bold="True" />

<Columns>
<asp:BoundColum n HeaderText="Tit le" DataField="titl e" />
<asp:BoundColum n HeaderText="Aut hor" DataField="auth or" />
<asp:BoundColum n HeaderText="Yea r" DataField="year " />
</Columns>
</asp:datagrid>

</body>
</html>

and here's my xml file:

<?xml version="1.0" encoding="UTF-8" ?>
<books>
- <book>
<title>Teach Yourself Active Server Pages 3.0 in 21 Days</title>
<author>Mitchel l</author>
<year>1999</year>
</book>
- <book>
<title>Designin g Active Server Pages</title>
<author>Mitchel l</author>
<year>2000</year>
</book>
- <book>
<title>ASP.NE T: Tips, Tutorials, and Code</title>
<author>Mitchel l</author>
<year>2001</year>
</book>
- <book>
<title>ASP Unleashed</title>
<author>Walther </author>
<year>1998</year>
</book>
- <book>
<title>ASP.NE T Unleashed</title>
<author>Walther </author>
<year>2002</year>
</book>
- <book>
<title>Creati ng Data Driven ASP.NET Applications</title>
<author>Seven </author>
<year>2002</year>
</book>
</books>

>
Dim myDataSet as New DataSet()
myDataSet.ReadX ml(Server.MapPa th("books.xml") )

http://aspnet.4guysfromrolla.com/articles/052902-1.aspx

http://www.google.com/search?hl=en&q...et+xml+asp.net

Jun 7 '07 #3
On Jun 7, 9:56 pm, slinky <campbellbrian2 ...@yahoo.comwr ote:
try to view it in my browser and I get server errors:
:-)

What errors do you get?

Jun 7 '07 #4
I figured it out. I set the web.config file to <customErrors
mode="Off"/>
then noticed the error saying the app could not find the xml file
because I had it in my App_Data folder.
So I moved it to the remote host folder and it works fine now. Thanks
for helping me up the steep hill
of understanding reading XML files as data into my apps.

BTW... since (correct me if I'm wrong) ALL data is ultimately sent
over the internet as XML files,
is there an advantage in using them as your relational database to
start with? I know the markup
makes them rather verbose, but would not in reality a SQLserver file
be turned into an XML file
for moving over the net?... Kind of an academic question, just
curious... Thanks!
On Jun 7, 6:15 pm, Alexey Smirnov <alexey.smir... @gmail.comwrote :
On Jun 7, 9:56 pm, slinky <campbellbrian2 ...@yahoo.comwr ote:
try to view it in my browser and I get server errors:

:-)

What errors do you get?

Jun 8 '07 #5
On Jun 8, 2:51 pm, slinky <campbellbrian2 ...@yahoo.comwr ote:
BTW... since (correct me if I'm wrong) ALL data is ultimately sent
over the internet as XML files,
is there an advantage in using them as your relational database to
start with? I know the markup
makes them rather verbose, but would not in reality a SQLserver file
be turned into an XML file
for moving over the net?... Kind of an academic question, just
curious... Thanks!
All data sent over the internet are sent in the binary packets :-)

XML can be useful a number of reasons: easy to edit, lightweight, no
additional license costs and so on. Database is secure, easy to
search, efficient for large data sets...

http://www.google.com/search?q=xml+vs+database

Jun 8 '07 #6
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!

On Jun 8, 10:54 am, Alexey Smirnov <alexey.smir... @gmail.comwrote :
On Jun 8, 2:51 pm, slinky <campbellbrian2 ...@yahoo.comwr ote:
BTW... since (correct me if I'm wrong) ALL data is ultimately sent
over the internet as XML files,
is there an advantage in using them as your relational database to
start with? I know the markup
makes them rather verbose, but would not in reality a SQLserver file
be turned into an XML file
for moving over the net?... Kind of an academic question, just
curious... Thanks!

All data sent over the internet are sent in the binary packets :-)

XML can be useful a number of reasons: easy to edit, lightweight, no
additional license costs and so on. Database is secure, easy to
search, efficient for large data sets...

http://www.google.com/search?q=xml+vs+database

Jun 8 '07 #7
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

Jun 8 '07 #8
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

Jun 11 '07 #9
On Jun 11, 5:40 pm, slinky <campbellbrian2 ...@yahoo.comwr ote:
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....
Open the example I've sent you.

Where did you found a HtmlTextWriter?

Change it to XMLTextWriter.

Add a reference to System.XML namespace

<%@ Import Namespace="Syst em.XML" %>

and add an OnClick() event

<asp:Button ID="btnWriteXML " runat="server" Text="Button"
OnClick="btnWri teXML_OnClick" />

Jun 11 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2713
by: rdemyan via AccessMonster.com | last post by:
My App has 10 or so tables that we provide that contains proprietary data. This data will need to be updated once or twice a year. I would like some comments, suggestions on my proposed strategy for updating these tables via an ftp site: 1) Post a .mdb file to our ftp web site that contains the updated tables. My App code connects to the ftp site and gets the file name for any update files on the site. I already have code to do this...
3
4632
by: John Morgan | last post by:
I have my first small SQl Server 2005 database developed on my local server and I have also its equivalent as an online database. I wish to update the local database (using and asp.net interface) and then to upload the data (at least the amended data, but given the small size all data should be no trouble) to the online database. I think replication is the straight answer but I have no experience of this and I am wondering what else...
3
4915
by: =?Utf-8?B?QnJhbmRvbg==?= | last post by:
Hi, I have an aspx page that has the "include" code in it which includes another page that displays information. I also have an upload page that allows users to upload a simple html document onto the server. The include code calls that html page to display the text on that page. The problem is when the user uploads that html page, the aspx page does not refresh to reflect those changes, even if the user hits refresh in their browse....
3
1330
by: slinky | last post by:
I have an aspx for with a textbox and a button. The goal is to simply have the user type a message, hit the button and it should append to the XML file. I can open the aspx in the browser with no problem, but the XML file does not get updated. What's wrong with this code? Thanks! <script runat="server"> Private Sub Page_Load(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles MyBase.Load If Not IsPostBack Then
0
8385
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8303
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8723
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8602
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7316
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6162
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5632
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2726
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1941
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.