So - I guess my impression of XML as a pathetic academic naval gazing
exercise is confirmed.
I have concluded that the reason I cannot find a god example on how to
replace an INI file with a XML file is because the tool is too weak.
I have always wonder about the strange example files used to demo/teach XML
in that they always seemed to be worthless as data records. Now I understand
the examples were designed to support what XML can do, which is very little
when it comes to storing data.
Amazing, all that "elegant" design and it can't even replace a simple INI
file.
[quoted text, click to view] "Bob Heitzman" wrote:
> I need to store data in, update, and read data from an XML file.
>
> An INI structure worked fine:
>
> [Zone 01]
> a= 123
> b= xyz
> c= etc
>
> [Zone 02]
> ....
>
> I've been look around the net and cannot find a simple comprehesive example
> on how to convert this to VB.Net and System.Xml. Biggest problem is that the
> sample files do not seem to be structure such that the data can be retrived
> by "zone name" from the above example.
>
> First issue is how do I structure the XML file to make updates and queries?
>
> I'm working with this design currently:
>
> <Zones>
> <Zone Name="Zone 01">
> <a>123</a>
> <b>xyz</c>
> <c>etc</c>
> </Zone>
> <Zone Name="Zone 02">
> <a>2</a>
> ...
> </Zones>
>
> Is this a good layout for SIMPLE adds, updates and reading?
>
> I'm really lost beyond the layout too - I'm thinking SelectNodes and
> SelectSingleNodes is the way to go to get data out but I can't get any XPATH
> strings to work with the above design.
>
> Haven't a clue on adds and updates.
>
> Should I be using a different design? I need to work with the data a "zone"
> at a time, usually only one zone during a session.
>
> Does anyone know of a good book/sample/white paper that addresses the above
> application in VB?
>
> Or perhaps this is simple enough a few examples of adds(new zones), updates,
> and reads could be posted?
>
Figured out the soultion was to not use .Net SQL to work with records in a
XML formated data file. Used dataset instead. Using the dataset bound to a
DataGridView allowed for in place edit, adds, and deletes. Need a seed file
to get started (or go through the effort to expand solution to use schemas.
Imports System.IO
Public Class Form1
Dim ds As DataSet
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
ds = New DataSet
ds.ReadXml("C:\DevVS2005\XML_Test\XML_Test\XMLFile1.xml")
dgv1.DataSource = ds
dgv1.DataMember = "Authors"
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
ds.WriteXml("C:\DevVS2005\XML_Test\XML_Test\XMLFile1.xml")
End Sub
End Class
Typical data:
<Authors_Table>
<authors>
<au_id>172-32-1176</au_id>
<au_lname>Blue</au_lname>
<au_fname>Johnson</au_fname>
<phone>408 496-7223</phone>
<address>10932 Bigge Rd.</address>
<city>Menlo Park</city>
<state>CA</state>
<zip>94025</zip>
<contract>true</contract>
</authors>
....