Form to edit XML records

  • Thread starter Thread starter Brock
  • Start date Start date
B

Brock

I have an .aspx page that is successfully (I use Visual Web Developer
2008) reading an XML file and displaying the records on a datagrid
using:

<script runat="server">
Private Function MakeDataView() as DataView
Dim myDataSet As New DataSet()
myDataSet.ReadXml(Server.MapPath("history.xml"))
Dim view As DataView = New DataView(myDataSet.Tables(0))
view.AllowDelete = False
view.AllowEdit = False
view.AllowNew = False
Return view
End Function

Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
Dim view as DataView = MakeDataView()
dgHistory.DataSource = view
dgHistory.AllowSorting = True
dgHistory.DataBind()
Label1.Text = DateAndTime.Now.ToLongTimeString

End Sub
</script>

Can anyone give me some clues as to how to code another .aspx page to
query the XML using XPathNavigator tools to find a specific record
based on an ID number? The goal is to have the user be able to click
on an edit button and it will launch an edit page passing that record
to the edit page.

I really need a separate edit page because the number of fields is
over 50 and the datagrid in the base form only displays about 4
fields.

I'm thinking I might be able to use a detailsView on my main page that
would appear below the datagrid when a user clicks on the edit
button.

Thanks!!
 
I'm kinda new to detailview and querying a specific record so I need
to start with something a little more simple.

I have another page with a grid that has just two fields (the XML file
has only two also - one is a record number). I went ahead and placed a
column in the grid with the underlined word "Edit" for the users.

I want this event on the "Edit" to query the actual XML file and
display the data from the data field (not the record number) into a
text box under the grid.

I then want to have a button beside the textbox that will write the
changes back to the actual XML file.

This is really just a learning exercize for me but I need a little
guidance.... much appreciated!!!
 
Actually the XPathNavigator to query the XML file has me stumped plus
getting the query to run upon the hitting the edit button. So far in
those examples I haven't seen anything.
 
Brock since you're learning this objective at this point in time you should
be learning LINQ to XML. And I've also found the ASP.NE 2.0 Wizard control
to be very good for editing XML itself. I've used the Wizard Control to
build an RSS feed generator. While not complete and has a rather steep
learning curve --at first-- the Wizard control IMO provides much more
flexibility in the UI than any of the other controls for CRUD of data that
is really linear in a workflow even though XML is represented as a tree in
the UI; creating and managing the data itself remains a linear work-flow and
the Wizard (or Multiview control that the Wizard is built from) works very
well for many steps involved in editing linear work-flows.

So here is my suggestion:

* LINQ to XML
* ASP.NET 2.0 Wizard control or MultiView control


Actually the XPathNavigator to query the XML file has me stumped plus
getting the query to run upon the hitting the edit button. So far in
those examples I haven't seen anything.
 
I guess for right now I just need to know how to use the "SELECT....
FROM... WHERE... =" in my code to select a specific 'record' from my
XML file

<script runat="server">
Private Function MakeDataView() as DataView
Dim myDataSet As New DataSet()
myDataSet.ReadXml(Server.MapPath("history.xml"))
Dim view As DataView = New DataView(myDataSet.Tables(0))
view.AllowDelete = False
view.AllowEdit = False
view.AllowNew = False
Return view
End Function
Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
Dim view as DataView = MakeDataView()
dgHistory.DataSource = view
dgHistory.AllowSorting = True
dgHistory.DataBind()
Label1.Text = DateAndTime.Now.ToLongTimeString
End Sub
</script>
 
Half the battle is learning the right search terms. What you call a record
is called a node in XML. As I'm learning myself this search query has proven
very insightful

linq to xml select node from file

I guess for right now I just need to know how to use the "SELECT....
FROM... WHERE... =" in my code to select a specific 'record' from my
XML file

<script runat="server">
Private Function MakeDataView() as DataView
Dim myDataSet As New DataSet()
myDataSet.ReadXml(Server.MapPath("history.xml"))
Dim view As DataView = New DataView(myDataSet.Tables(0))
view.AllowDelete = False
view.AllowEdit = False
view.AllowNew = False
Return view
End Function
Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
Dim view as DataView = MakeDataView()
dgHistory.DataSource = view
dgHistory.AllowSorting = True
dgHistory.DataBind()
Label1.Text = DateAndTime.Now.ToLongTimeString
End Sub
</script>
 
Back
Top