473,218 Members | 1,415 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,218 software developers and data experts.

edit shared XML via asp.net page and save back to server.

I have a shared XML file on a server .

i also have one xslt file that performs a simple transform on in to
view the data.

now i want to have another page that lets users modify the shared xml
file via some editable controls such as text boxes , option boxes etc.

how can i implment this , should i use another xslt file with <INPUT>
controls . if so how can i save the result back using the asp.net
page.

or should i use asp.net to drive the whole page and not use an xslt
file . again , any pointers on how to do this would be useful.

thanks

glenn
Nov 18 '05 #1
4 3676
I would stick with the ASP.NET approach. The DataGrid/DataSet has native XML support. You could populate the DataGrid with the XML file, allow users to edit the information inside of the DataGrid, and then save the XML file. OR -> You could create a custom object(s) that represent the XML file and serialize and deserialize the XML as necessary. In that form, you could continue to use text boxes, drop down lists, data grids, etc.

"Glenn M" wrote:
I have a shared XML file on a server .

i also have one xslt file that performs a simple transform on in to
view the data.

now i want to have another page that lets users modify the shared xml
file via some editable controls such as text boxes , option boxes etc.

how can i implment this , should i use another xslt file with <INPUT>
controls . if so how can i save the result back using the asp.net
page.

or should i use asp.net to drive the whole page and not use an xslt
file . again , any pointers on how to do this would be useful.

thanks

glenn

Nov 18 '05 #2
First, there is no reason to reinvent the wheel, if you are alredy using an
xslt transform and it does everything you need it to do, leave it alone. On
your edit page you could use an xmldocument object to write/save the data in
the xml document. When the user displays the "View" page the xlst will
reload the xml file and display the edited/updated information. Make sure
the authentication method you have chosen has write access to the xml file,
I used "everyone - write".

Here is a working sample
There are six files in this example, two webforms (View.aspx, Edit.aspx),
two code behinds, an xml document and an xlst file. Set View.aspx as the
startup page.

Hope this helps.

'View.aspx
<HTML>
<HEAD>
<title>Default</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5"
name="vs_targetSchema">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
&nbsp;
<asp:button id="btnEdit" style="Z-INDEX: 101; LEFT: 12px; POSITION:
absolute; TOP: 13px" runat="server"
Text="Edit" Width="102px"></asp:button></form>
</body>
</HTML>

' End View.aspx

'View.aspx.vb
Public Class View
Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()

End Sub
Protected WithEvents btnEdit As System.Web.UI.WebControls.Button

'NOTE: The following placeholder declaration is required by the Web Form
Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
If Not IsPostBack Then
Dim doc As New System.Web.UI.WebControls.Xml
Me.Controls.Add(doc)
doc.DocumentSource = "Books.xml"
doc.TransformSource = "Books.xslt"
End If
End Sub

Private Sub btnEdit_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnEdit.Click
Response.Redirect("edit.aspx")
End Sub
End Class

' End View.aspx.vb

'Edit.aspx
<HTML>
<HEAD>
<title>Edit</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5"
name="vs_targetSchema">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<div>
<asp:DropDownList id="lstBooks" runat="server" Width="189px"
AutoPostBack="True"></asp:DropDownList>
<asp:Button id="btnSave" runat="server" Width="131px"
Text="Save"></asp:Button>
<asp:Button id="btnDone" runat="server" Width="131px"
Text="Finished"></asp:Button>
</div>
<div>
<table runat="server">
<tr width="100%">
<td width="30%">Author</td>
<td runat="server">
<asp:TextBox id="txtAuthor" runat="server"
Width="100%"></asp:TextBox></td>
</tr>
<tr width="100%">
<td width="30%">Title</td>
<td>
<asp:TextBox id="txtTitle" runat="server"
Width="100%"></asp:TextBox></td>
</tr>
<tr width="100%">
<td width="30%">Genre</td>
<td>
<asp:TextBox id="txtGenre" runat="server"
Width="100%"></asp:TextBox></td>
</tr>
<tr width="100%">
<td width="30%">Price</td>
<td>
<asp:TextBox id="txtPrice" runat="server"
Width="100%"></asp:TextBox></td>
</tr>
<tr width="100%">
<td width="30%">Date Published</td>
<td>
<asp:TextBox id="txtPubDate" runat="server"
Width="100%"></asp:TextBox></td>
</tr>
<tr width="100%">
<td width="30%">Description</td>
<td>
<asp:TextBox id="txtDescription" runat="server" Width="100%"
TextMode="MultiLine"></asp:TextBox></td>
</tr>
</table>
</div>
</form>
</body>
</HTML>

'End Edit.aspx

'Edit.aspx.vb
Public Class Edit
Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()

End Sub
Protected WithEvents btnSave As System.Web.UI.WebControls.Button
Protected WithEvents lstBooks As System.Web.UI.WebControls.DropDownList
Protected WithEvents txtAuthor As System.Web.UI.WebControls.TextBox
Protected WithEvents txtTitle As System.Web.UI.WebControls.TextBox
Protected WithEvents txtGenre As System.Web.UI.WebControls.TextBox
Protected WithEvents txtPrice As System.Web.UI.WebControls.TextBox
Protected WithEvents txtPubDate As System.Web.UI.WebControls.TextBox
Protected WithEvents txtDescription As System.Web.UI.WebControls.TextBox
Protected WithEvents btnDone As System.Web.UI.WebControls.Button

'NOTE: The following placeholder declaration is required by the Web Form
Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub

#End Region

Dim xDoc As System.Xml.XmlDocument

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
If Not IsPostBack _
AndAlso (Session.Item("IsDirty") = True _
OrElse Session.Item("IsDirty") Is Nothing) Then
xDoc = New System.Xml.XmlDocument
xDoc.Load(Server.MapPath("Books.xml"))
Dim Nodes As System.xml.XmlNodeList = xDoc.SelectNodes("//book")
For Each Node As System.Xml.XmlNode In Nodes
Me.lstBooks.Items.Add(Node.Item("title").InnerText )
Next
LoadData()
Session.Item("IsDirty") = False
End If

End Sub

Private Sub LoadData()
Me.txtAuthor.Text = GetElement("author")
Me.txtDescription.Text = GetElement("description")
Me.txtGenre.Text = GetElement("genre")
Me.txtPrice.Text = GetElement("price")
Me.txtPubDate.Text = GetElement("publish_date")
Me.txtTitle.Text = GetElement("title")
End Sub
Private Function GetElement(ByVal TagName As String) As String
If xDoc Is Nothing Then
xDoc = New System.Xml.XmlDocument
xDoc.Load(Server.MapPath("Books.xml"))
End If
Dim Path As String = "//book[title=""" & Me.lstBooks.SelectedValue &
"""]"
Dim Node As System.Xml.XmlNode = xDoc.SelectSingleNode(Path)
Return Node.Item(TagName).InnerText
End Function

Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnSave.Click
If xDoc Is Nothing Then
xDoc = New System.Xml.XmlDocument
xDoc.Load(Server.MapPath("Books.xml"))
End If
Dim Path As String = "//book[title=""" & Me.lstBooks.SelectedValue &
"""]"
Dim node As System.Xml.XmlNode = xDoc.SelectSingleNode(Path)
With node
.Item("title").InnerText = Me.txtTitle.Text
.Item("author").InnerText = Me.txtAuthor.Text
.Item("description").InnerText = Me.txtDescription.Text
.Item("publish_date").InnerText = Me.txtPubDate.Text
.Item("price").InnerText = Me.txtPrice.Text
.Item("genre").InnerText = Me.txtGenre.Text
End With
xDoc.Save(Server.MapPath("books.xml"))
Session.Item("IsDirty") = True
End Sub

Private Sub lstBooks_SelectedIndexChanged(ByVal sender As Object, ByVal
e As System.EventArgs) Handles lstBooks.SelectedIndexChanged
LoadData()
End Sub

Private Sub btnDone_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnDone.Click
Response.Redirect("view.aspx")
End Sub
End Class

'End Edit.aspx.vb

'Books.xslt
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="catalog">
<HTML>
<BODY>
<TABLE BORDER="2">
<TR>
<TD>Title</TD>
<TD>Author</TD>
<TD>Genre</TD>
<TD>Price</TD>
<TD>Date Published</TD>
<TD>Description</TD>
</TR>
<xsl:for-each select="book">
<TR>
<TD><xsl:value-of select="title"/></TD>
<TD><xsl:value-of select="author"/></TD>
<TD><xsl:value-of select="genre"/></TD>
<TD><xsl:value-of select="price" /></TD>
<TD><xsl:value-of select="publish_date" /></TD>
<TD><xsl:value-of select="description" /></TD>
</TR>
</xsl:for-each>
</TABLE>
</BODY>
</HTML>
</xsl:template>
</xsl:stylesheet>

'End Books.xslt

'Books.xml
<?xml version="1.0"?>
<catalog>
<book id="bk101">
<author>Gambardella, Matthew</author>
<title>XML Developer's Guide</title>
<genre>Computer</genre>
<price>44.95</price>
<publish_date>2000-10-01</publish_date>
<description>An in-depth look at creating applications
with XML.</description>
</book>
<book id="bk102">
<author>Ralls, Kim</author>
<title>Midnight Rain</title>
<genre>Fantasy</genre>
<price>5.95</price>
<publish_date>2000-12-16</publish_date>
<description>A former architect battles corporate zombies,
an evil sorceress, and her own childhood to become queen
of the world.</description>
</book>
<book id="bk103">
<author>Corets, Eva</author>
<title>Maeve Ascendant</title>
<genre>Fantasy</genre>
<price>5.95</price>
<publish_date>2000-11-17</publish_date>
<description>After the collapse of a nanotechnology
society in England, the young survivors lay the
foundation for a new society.</description>
</book>
<book id="bk104">
<author>Corets, Eva</author>
<title>Oberon's Legacy</title>
<genre>Fantasy</genre>
<price>5.95</price>
<publish_date>2001-03-10</publish_date>
<description>In post-apocalypse England, the mysterious
agent known only as Oberon helps to create a new life
for the inhabitants of London. Sequel to Maeve
Ascendant.</description>
</book>
<book id="bk105">
<author>Corets, Eva</author>
<title>The Sundered Grail</title>
<genre>Fantasy</genre>
<price>5.95</price>
<publish_date>2001-09-10</publish_date>
<description>The two daughters of Maeve, half-sisters,
battle one another for control of England. Sequel to
Oberon's Legacy.</description>
</book>
<book id="bk106">
<author>Randall, Cynthia</author>
<title>Lover Birds</title>
<genre>Romance</genre>
<price>4.95</price>
<publish_date>2000-09-02</publish_date>
<description>When Carla meets Paul at an ornithology
conference, tempers fly as feathers get ruffled.</description>
</book>
<book id="bk107">
<author>Thurman, Paula</author>
<title>Splish Splash</title>
<genre>Romance</genre>
<price>4.95</price>
<publish_date>2000-11-02</publish_date>
<description>A deep sea diver finds true love twenty
thousand leagues beneath the sea.</description>
</book>
<book id="bk108">
<author>Knorr, Stefan</author>
<title>Creepy Crawlies</title>
<genre>Horror</genre>
<price>4.95</price>
<publish_date>2000-12-06</publish_date>
<description>An anthology of horror stories about roaches,
centipedes, scorpions and other insects.</description>
</book>
<book id="bk109">
<author>Kress, Peter</author>
<title>Paradox Lost</title>
<genre>Science Fiction</genre>
<price>6.95</price>
<publish_date>2000-11-02</publish_date>
<description>After an inadvertant trip through a Heisenberg
Uncertainty Device, James Salway discovers the problems
of being quantum.</description>
</book>
<book id="bk110">
<author>O'Brien, Tim</author>
<title>Microsoft .NET: The Programming Bible</title>
<genre>Computer</genre>
<price>36.95</price>
<publish_date>2000-12-09</publish_date>
<description>Microsoft's .NET initiative is explored in
detail in this deep programmer's reference.</description>
</book>
<book id="bk111">
<author>O'Brien, Tim</author>
<title>MSXML3: A Comprehensive Guide</title>
<genre>Computer</genre>
<price>36.95</price>
<publish_date>2000-12-01</publish_date>
<description>The Microsoft MSXML3 parser is covered in
detail, with attention to XML DOM interfaces, XSLT processing,
SAX and more.</description>
</book>
<book id="bk112">
<author>Galos, Mike</author>
<title>Visual Studio 7: A Comprehensive Guide</title>
<genre>Computer</genre>
<price>49.95</price>
<publish_date>2001-04-16</publish_date>
<description>Microsoft Visual Studio 7 is explored in depth,
looking at how Visual Basic, Visual C++, C#, and ASP+ are
integrated into a comprehensive development
environment.</description>
</book>
</catalog>

'End Books.xml

"Glenn M" <gl**********@bt.com> wrote in message
news:32**************************@posting.google.c om...
I have a shared XML file on a server .

i also have one xslt file that performs a simple transform on in to
view the data.

now i want to have another page that lets users modify the shared xml
file via some editable controls such as text boxes , option boxes etc.

how can i implment this , should i use another xslt file with <INPUT>
controls . if so how can i save the result back using the asp.net
page.

or should i use asp.net to drive the whole page and not use an xslt
file . again , any pointers on how to do this would be useful.

thanks

glenn

Nov 18 '05 #3
Thanks for that.

I have another question , i have a vbscript on server1 that parses an
xml file from my web server sever2 (http:\\server2\myxml.xml)

The vbscript collects information from the server and amends the xml dom
object when a new record needs to be added or old one removed.

Now i want want to persist that xml back to the web server , and as we
know i can't save back directly. Any idea how i can work around this.

I was thinking of setting up a web sevice on the server or maybe feeding
the xml stream stream into an ASP.net page that would save it to the xml
file.

(alas the vbscript must reside on server1 and the xml file on sever2 )

any starting points to look at would be really useful.

glenn

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 18 '05 #4
Glenn,
Why can't you save the back to the web server? Do you mean it is
physically impossible; or you don't want to make security permission changes
to the virtual directory/file that needs to be updated? If you give write
access to the account the script runs against you shouldn't have a problem
modifying the script as long as you aren't trying to delete the file and
create a new one each time. You can use a web service as you suggested,
but, you will still have to account for security permissions which would
essentially do the same as modifying the DACL on the file itself. Is you
web server available to the public, or an Intranet server? Does your site
run under the IUSER account, Basic, or Windows auth? Can \\server1 access
\\server2 vice versa ? I have written web applications that will write xml
files to a different physical location, the only obstacle I have come across
is physical file security.

I would first try to modify the permissions on
\\server2\wwwroot$\your_virtual_directory\xmlfile. xml, make sure the user
account running the script can write to it. Modify your script to make the
necessary changes in the xml file via the XMLDOM object and you should be
good to go. If you want to replace \\server2\myxml.xml with the newly
generated copy from \\server1 then you will need to grant modify permissions
to the virtual directory where the file is stored and modify your script to
include:

set FSO = CreateObject("Scripting.FileSystemObject")
Set MyXMLFile = FSO.GetFile("C:\MyXML.xml")
MyXMLFile.Copy ("\\Server2\wwwroot$\your_virtual_directory\MyXML. xml", True)
'True = Overwrite

Post your results, or any other details.
Jared
"Glenn Mantle" <gl**********@bt.com> wrote in message
news:Oe*************@TK2MSFTNGP11.phx.gbl...
Thanks for that.

I have another question , i have a vbscript on server1 that parses an
xml file from my web server sever2 (http:\\server2\myxml.xml)

The vbscript collects information from the server and amends the xml dom
object when a new record needs to be added or old one removed.

Now i want want to persist that xml back to the web server , and as we
know i can't save back directly. Any idea how i can work around this.

I was thinking of setting up a web sevice on the server or maybe feeding
the xml stream stream into an ASP.net page that would save it to the xml
file.

(alas the vbscript must reside on server1 and the xml file on sever2 )

any starting points to look at would be really useful.

glenn

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 18 '05 #5

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

Similar topics

6
by: matt | last post by:
I am using a text file as a database, each field delimited by || I want to be able to print all lines to a page, then by selecting one (with, say, a radio button) it will load into the form at the...
3
by: sygsix | last post by:
Hello all. I am a Java programmer who sometimes dabbles in simple PHP stuff, and had a question that's way over my head, for you DHTML experts. I would like to know how to dynamically edit a...
2
by: John Lau | last post by:
Hi, Is there documentation that talks about the page lifecycle, the lifecycle of controls on the page, and the rendering of inline code, in a single document? Thanks, John
1
by: Ather Ali Shaikh | last post by:
Hi all, How can I edit an Image opened in the browsers and saves it with a new name. The scenario is that I received an email having some attached documents in the image format. I read that...
6
by: scottyman | last post by:
I can't make this script work properly. I've gone as far as I can with it and the rest is out of my ability. I can do some html editing but I'm lost in the Java world. The script at the bottom of...
1
by: Stephen Lynch | last post by:
What is the best way to insure that an edit table fields are saved on an exit. For example, I have an edit panel on a page. I do not want to post back on every field, but if an end user goes to...
1
by: rp13 | last post by:
Hi, I am using a asp:datagrid which is editable. Though I have handlers wired to my edit, update & cancel events, some how when i click on the edit button nothing happens. The edit template...
5
by: JohnSouth | last post by:
Hi I've seen lots of posts around this subject but nothing recent or very helpful. I've an ASP.Net c# application that needs to read Word documents from a directory on the web server, open...
9
by: rn5a | last post by:
A Form has a DataGrid which displays records from a SQL Server 2005 DB table. Users can modify the records using this DataGrid for which I am using EditCommandColumn in the DataGrid. This is the...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...

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.