|
-
Dec 22nd, 2009, 02:40 PM
#1
Thread Starter
Lively Member
Problem loading XML Document?
Hi, I was making a favorites tree browser, but saving an XML Document seems to have a little bit of trouble
Items in my treenode that are in groups save and load properly, but single favorites are lost when i reopen forms. I looked throughout the code for hours but cant seem to find the error, can someone else see the problem? thanks
Private Sub MainForm_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
Dim xdoc As New Xml.XmlDocument
Dim root As Xml.XmlElement = xdoc.CreateElement("Favorites")
xdoc.AppendChild(root)
For Each tn As TreeNode In FavoritesTreeView.Nodes
If tn.Tag.ToString = "#GROUP#" Then
Dim ge As Xml.XmlElement = xdoc.CreateElement("Group")
Dim att As Xml.XmlAttribute = xdoc.CreateAttribute("name")
att.Value = tn.Text
ge.Attributes.Append(att)
For Each cn As TreeNode In tn.Nodes
Dim ee As Xml.XmlElement = xdoc.CreateElement("Entry")
Dim atr As Xml.XmlAttribute
atr = xdoc.CreateAttribute("name")
atr.Value = cn.Text
ee.Attributes.Append(atr)
atr = xdoc.CreateAttribute("url")
atr.Value = cn.Tag.ToString
ee.Attributes.Append(atr)
ge.AppendChild(ee)
Next
root.AppendChild(ge)
Else
Dim ee As Xml.XmlElement = xdoc.CreateElement("Entry")
Dim atr As Xml.XmlAttribute
atr = xdoc.CreateAttribute("name")
atr.Value = tn.Text
ee.Attributes.Append(atr)
atr = xdoc.CreateAttribute("url")
atr.Value = tn.Tag.ToString
ee.Attributes.Append(atr)
root.AppendChild(ee)
End If
Next
xdoc.Save(FavFile)
End Sub
Private Sub MainForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If ShowPreviewToolStripButton.Checked Then
If MainSplitContainer.Panel1Collapsed Then MainSplitContainer.Panel1Collapsed = False
Else
If Not ShowFavoritesToolStripButton.Checked And Not ShowPreviewToolStripButton.Checked Then
MainSplitContainer.Panel1Collapsed = True
Else
MainSplitContainer.Panel1Collapsed = False
End If
End If
NavBarSplitContainer.Panel1Collapsed = Not ShowPreviewToolStripButton.Checked
NavBarSplitContainer.Panel2Collapsed = Not ShowFavoritesToolStripButton.Checked
CurBrowser = WebBrowser1
CurBrowser.Tag = Page1BrowserPreview
Page1BrowserPreview.Tag = MainTabControl.SelectedTab
Page1BrowserPreview.Selected = True
If System.IO.File.Exists(FavFile) Then
Dim xdoc As New Xml.XmlDocument
xdoc.Load(FavFile)
Dim root As Xml.XmlElement = xdoc.Item("Favorites")
For Each elm As Xml.XmlElement In root
Select Case elm.Name
Case "Single"
Dim tn As New TreeNode
tn.Name = elm.Attributes("name").Value
tn.Text = elm.Attributes("name").Value
tn.Tag = elm.Attributes("url").Value
FavoritesTreeView.Nodes.Add(tn)
Case "Group"
Dim mtn As New TreeNode
mtn.Name = elm.Attributes("name").Value
mtn.Text = mtn.Name
mtn.Tag = "#GROUP#"
For Each ent As Xml.XmlElement In elm
Dim tn As New TreeNode
tn.Name = ent.Attributes("name").Value
tn.Text = ent.Attributes("name").Value
tn.Tag = ent.Attributes("url").Value
mtn.Nodes.Add(tn)
Next
FavoritesTreeView.Nodes.Add(mtn)
End Select
Next
End If
If My.Application.CommandLineArgs.Count > 0 Then
Dim first As Boolean = True
For Each str As String In My.Application.CommandLineArgs
AddressToolStripComboBox.Text = str
If first Then
GoToolStripDropDownButton.PerformButtonClick()
first = False
Else
GoNewTabToolStripMenuItem.PerformClick()
End If
Next
While Not CurBrowser.IsBusy
My.Application.DoEvents()
End While
Else
CurBrowser.GoHome()
End If
PreviewRefreshButton.PerformClick()
End Sub
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|