XML Reading
when my menu drops down it initiates the following code:
| | Dim desktopDirAsString = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)Dim dirAsNew DirectoryInfo(Path.Combine(desktopDir,"C:\Documentsand Settings\******\Desktop\Unlimited\"))ForEach fileAs FileInfoIn dir.GetFiles("*.xml")ProcessXml(file.FullName) NextEndSubPrivateSub ProcessXml(ByVal fileNameAsString)TryDim settingsXmlAsNew System.Xml.XmlDocumentsettingsXml.Load(fileName) Dim catagoryNameAs System.Xml.XmlNodeDim progNameAs System.Xml.XmlNodeForEach nodeAs Xml.XmlNodeIn settingsXml.SelectNodes("cata")catagoryName = node.SelectSingleNode( "name")progName = node.SelectSingleNode( "progname")Dim myMenuItemFileAsNew ToolStripMenuItem(catagoryName.InnerText)Dim myMenuItemNewAsNew ToolStripMenuItem(progName.InnerText)themenu.DropDownItems.Add(myMenuItemFile) myMenuItemFile.DropDownItems.Add(myMenuItemNew) NextCatch exAs ExceptionEndTryEndSub
|
This code works fine, heres my xml structure:
| | <?xml version="1.0" encoding="utf-8"?><cata> <name>Yes</name> <progname>great</progname> </cata>
|
But if i add another progname i also want it to show up in the catagory, and if i added another, an another and so on
So what im saying if my xml looked like this:
| | <?xml version="1.0" encoding="utf-8"?><cata> <name>Yes</name> <progname>great</progname> <progname>great</progname> <progname>great</progname> <progname>great</progname> <progname>great</progname> <progname>great</progname> <progname>great</progname> <progname>great</progname> </cata>
|
It would add all the <prognames> to the <name>
Any ideas?
hi,
i'm not expert i'm learning like you , but i guess you can't build xml document like that i guess you have a problem in the name node i think you have to add it to your cata as atripute and like that this xml will be valid like that
| | <cata cataname="yes"> <progname>great</progname> <progname>great</progname> <progname>great</progname> </cata>
|
and you can read it as attripute
| | catagoryName = node.SelectSingleNode("@cataname")
|
then you can loop through your node childrens
this is my opinion and as i told you i'm still learning as well as you:)
So you have a document like this:
<?xml version="1.0" encoding="utf-8"?>
<cata>
<name>yes</name>
<progname>firstProgram</progname>
<progname>secondProgram</progname>
<progname>thirdProgram</progname>
<progname>fourthProgram</progname>
<progname>fifthProgram</progname>
<progname>sixthProgram</progname>
</cata>
Do you want on menu item with a sub item for each menu item that would look like this:
yes
|-firstProgram
|-secondProgram
|-thirdProgram
|-fourthProgram
|-fifthProgram
|-sixthProgram
if that is what you want you should do something like this:
Private Sub ProcessXml(ByVal fileName As String)
Try
Dim settingsXml As New XmlDocument
settingsXml.Load(fileName)
Dim catagoryName As XmlNode = node.SelectSingleNode("name")
For Each node As XmlNode In settingsXml.SelectNodes("cata")
For Each progName As XmlNode In node.SelectNodes("progname")
mi.DropDownItems.Add(New ToolStripMenuItem(progName.InnerText))
Next
Next
theMenu.DropDownItems.Add(mi)
Catch ex As Exception
End Try
End Sub
If that structure is not what you are going for, you will need to be more specifc about what you are trying to do.