TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Sindhu Venkat
NA
12
0
Treeview to XML
Sep 1 2009 2:24 AM
I want to convert treeview back to an xml. Here I attached my coding for treeview. I need to get an xml from this treeview. Itz Very urgent. Please help me out....
Sub
DisplayXmlFile(
ByVal
filename
As
String
,
ByVal
tvw
As
TreeView)
Dim
xmldoc
As
New
XmlDocument
xmldoc.Load(filename)
' Add it to the TreeView Nodes collection
DisplayXmlNode(xmldoc, tvw.Nodes)
' Expand the root node.
tvw.Nodes(0).Expand()
End
Sub
Sub
DisplayXmlNode(
ByVal
xmlnode
As
XmlNode,
ByVal
nodes
As
TreeNodeCollection)
' Add a TreeView node for this XmlNode.
' (Using the node's Name is OK for most XmlNode types.)
Dim
tvNode
As
TreeNode
If
xmlnode.Name =
"#comment"
Or
xmlnode.Name =
"#document"
Or
xmlnode.Name =
"xml"
Then
'skipping comment node
Else
tvNode = nodes.Add(xmlnode.Name)
tvNode.ForeColor = Color.Navy
End
If
Select
Case
xmlnode.NodeType
Case
XmlNodeType.Element
' This is an element: Check whether there are attributes.
If
xmlnode.Attributes.Count > 0
Then
' Create an ATTRIBUTES node.
tvNode.ForeColor = Color.Purple
Dim
attrNode
As
TreeNode = tvNode.Nodes.Add(
"ATTRIBUTES"
)
' Add all the attributes as children of the new node.
Dim
xmlAttr
As
XmlAttribute
For
Each
xmlAttr
In
xmlnode.Attributes
attrNode.ForeColor = Color.Green
' Each node shows name and value.
attrNode.Nodes.Add(xmlAttr.Name &
" = '"
& xmlAttr.Value & _
"'"
)
Next
End
If
Case
XmlNodeType.Text, XmlNodeType.CDATA
' For these node types we display the value
tvNode.Text = xmlnode.Value
Case
XmlNodeType.Comment
'tvNode.ForeColor = Color.White
'tvNode.Text = "<!--" & xmlnode.Value & "-->"
Case
XmlNodeType.ProcessingInstruction, XmlNodeType.XmlDeclaration
tvNode.ForeColor = Color.Red
tvNode.Text = "<?" & xmlnode.Name & " " & xmlnode.Value & "?>"
Case
Else
' ignore other node types.
End
Select
' Call this routine recursively for each child node.
Dim
xmlChild
As
XmlNode = xmlnode.FirstChild
Do
Until
xmlChild
Is
Nothing
If
tvNode
Is
Nothing
Then
DisplayXmlNode(xmlChild, nodes)
xmlChild = xmlChild.NextSibling
Else
DisplayXmlNode(xmlChild, tvNode.Nodes)
xmlChild = xmlChild.NextSibling
End
If
Loop
End
Sub
Reply
Answers (
1
)
Searching for Text through Treeview
Parsing XML file