Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > updating with aspx and XML file

Reply
Thread Tools

updating with aspx and XML file

 
 
slinky
Guest
Posts: n/a
 
      06-05-2007
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!

 
Reply With Quote
 
 
 
 
Alexey Smirnov
Guest
Posts: n/a
 
      06-05-2007
On Jun 5, 9:31 pm, slinky <campbellbrian2...@yahoo.com> wrote:
> 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.ReadXml(Server.MapPath("books.xml"))

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

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

 
Reply With Quote
 
 
 
 
slinky
Guest
Posts: n/a
 
      06-07-2007
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="System.Data" %>
<script runat="server">
sub Page_Load(sender as Object, e as EventArgs)
Dim myDataSet as New DataSet()

myDataSet.ReadXml(Server.MapPath("books.xml"))

dgBooks.DataSource = myDataSet
dgBooks.DataBind()

dgBooksPretty.DataSource = myDataSet
dgBooksPretty.DataBind()
end sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>StartPage</title>
</head>
<body>
<b>The Contents of the XML File
<a href="/demos/books.xml"><code>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"><code>books.xml</code></a></b><br />
</p>
<asp:datagrid id="dgBooksPretty" runat="server"
AutoGenerateColumns="False"
Font-Name="Verdana"
Font-Size="Small"
HorizontalAlign="Center"
ItemStyle-BackColor="#FFFFCC"
AlternatingItemStyle-BackColor="#EEEEEE">

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

<Columns>
<asp:BoundColumn HeaderText="Title" DataField="title" />
<asp:BoundColumn HeaderText="Author" DataField="author" />
<asp:BoundColumn HeaderText="Year" 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>Mitchell</author>
<year>1999</year>
</book>
- <book>
<title>Designing Active Server Pages</title>
<author>Mitchell</author>
<year>2000</year>
</book>
- <book>
<title>ASP.NET: Tips, Tutorials, and Code</title>
<author>Mitchell</author>
<year>2001</year>
</book>
- <book>
<title>ASP Unleashed</title>
<author>Walther</author>
<year>1998</year>
</book>
- <book>
<title>ASP.NET Unleashed</title>
<author>Walther</author>
<year>2002</year>
</book>
- <book>
<title>Creating Data Driven ASP.NET Applications</title>
<author>Seven</author>
<year>2002</year>
</book>
</books>




>
> Dim myDataSet as New DataSet()
> myDataSet.ReadXml(Server.MapPath("books.xml"))
>
> http://aspnet.4guysfromrolla.com/articles/052902-1.aspx
>
> http://www.google.com/search?hl=en&q...et+xml+asp.net



 
Reply With Quote
 
Alexey Smirnov
Guest
Posts: n/a
 
      06-07-2007
On Jun 7, 9:56 pm, slinky <campbellbrian2...@yahoo.com> wrote:
> try to view it in my browser and I get server errors:
>




What errors do you get?

 
Reply With Quote
 
slinky
Guest
Posts: n/a
 
      06-08-2007
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.com> wrote:
> On Jun 7, 9:56 pm, slinky <campbellbrian2...@yahoo.com> wrote:
>
> > try to view it in my browser and I get server errors:

>
>
>
> What errors do you get?



 
Reply With Quote
 
Alexey Smirnov
Guest
Posts: n/a
 
      06-08-2007
On Jun 8, 2:51 pm, slinky <campbellbrian2...@yahoo.com> wrote:
> 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

 
Reply With Quote
 
slinky
Guest
Posts: n/a
 
      06-08-2007
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.com> wrote:
> On Jun 8, 2:51 pm, slinky <campbellbrian2...@yahoo.com> wrote:
>
> > 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



 
Reply With Quote
 
Alexey Smirnov
Guest
Posts: n/a
 
      06-08-2007
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

 
Reply With Quote
 
slinky
Guest
Posts: n/a
 
      06-11-2007
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

 
Reply With Quote
 
Alexey Smirnov
Guest
Posts: n/a
 
      06-11-2007
On Jun 11, 5:40 pm, slinky <campbellbrian2...@yahoo.com> wrote:
> 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="System.XML" %>

and add an OnClick() event

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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Updating JTable Atomically - block data changes while updating. news.rcn.com Java 2 12-10-2007 11:49 AM
Newbie question about Java Updating and Inserting XML file ysongpsu@gmail.com Java 5 10-18-2007 05:38 AM
Different results parsing a XML file with XML::Simple (XML::Sax vs. XML::Parser) Erik Wasser Perl Misc 5 03-05-2006 10:09 PM
adding main.aspx.vb & main.aspx.resx under aspx John M ASP .Net 1 05-29-2005 09:27 PM
including one aspx file in another aspx file vish ASP .Net 2 07-16-2003 10:29 PM



Advertisments
 



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