Dataset - writing to XML / readinf from XML to dataset
I use a Dataset object containing 2 tables to read and write settings. Using the following code I write the XML file:
VB Code:
Sub SaveSettings()
'Purpose: Save settings to XML
Dim strFileName As String = My.Application.Info.Title & "Init.xml"
'Open the file if it exists
If System.IO.File.Exists(My.Application.Info.DirectoryPath & "\" & strFileName) Then
frmMain.dsProgramSettings.ReadXml(My.Application.Info.DirectoryPath & "\" & strFileName)
End If
'Create Dataset Row for Settings and assign values
Dim rowSettings As DataRow = frmMain.dsProgramSettings.Tables("Settings").NewRow
rowSettings("subDirs") = frmMain.chkSubDirs.CheckState
rowSettings("SaveDirs") = frmMain.chkSave.CheckState
' Add the record to the settings table
frmMain.dsProgramSettings.Tables("settings").Rows.Add(rowSettings)
'Create dataset Row for Directories to be saved
If SaveDirs And Not SelectedDirectories Is Nothing Then
Dim Dir As Short
For Dir = 0 To UBound(SelectedDirectories)
Dim rowDirs As DataRow = frmMain.dsProgramSettings.Tables("Dirs").NewRow
rowDirs("Dirname") = SelectedDirectories(Dir).ToString
frmMain.dsProgramSettings.Tables("Dirs").Rows.Add(rowDirs)
Next Dir
End If
' Update the XML file
frmMain.dsProgramSettings.WriteXml(strFileName)
End Sub
When I write data to the second table ("Dirs", containing 1 column "DirName")
the XML looks like this
VB Code:
<?xml version="1.0" standalone="yes"?>
<ProgramSettings>
<Settings>
<SubDirs>true</SubDirs>
<SaveDirs>Checked</SaveDirs>
</Settings>
<Dirs>
<DirName>c:\temp</DirName>
</Dirs>
<Dirs>
<DirName>c:\install</DirName>
</Dirs>
</ProgramSettings>
But I want it be like:
VB Code:
<?xml version="1.0" standalone="yes"?>
<ProgramSettings>
<Settings>
<SubDirs>true</SubDirs>
<SaveDirs>Checked</SaveDirs>
</Settings>
<Dirs>
<DirName>c:\temp</DirName>
<DirName>c:\install</DirName>
</Dirs>
</ProgramSettings>
I clearly am missing something cause i can't get it right! Any pointers?
Also, I want to write a XHTML file. How would I go about writing the extra tags needed for that (like <html></html> etc).
Thanks!
EDIT:
I just realized that this might normal behaviour cause for the settings table I am writing one row with multiple (two) columns whereas for the dirs table I am writing multiple rows of one column each.
So is the above xml represention correct ?
Re: writing XML file - rows for one section & XHTML
Could anyone please shed some light on this? :ehh: