Hello Daniweb-Community,

I got a node in my xml-File for a java-link. it looks like "C:\Program Files (x86)\Tool7\javaw.exe -splash:splash.png -cp ./cl/cl.jar; -Dawt.useSystemAAFontSettings=on"
If i start the tool by double click on the node, it doesn´t start it, because it doesn´t load the arguments.
Next i createt a new attribut (called Argument) in the xml-file at this node and the value in "Argumente" is "-splash:splash.png -cp ./cl/cl.jar; -Dawt.useSystemAAFontSettings=on". But it still doesn´t work.

So, it doesn´t read the attribut in the XML, but i don´t know why. I hope you can help me again? :)

Here is the XML-Code :

<?xml version="1.0" encoding="UTF-8"?>
<Programme Path="1">
  <Feld Icon="Folder.ico" Path="2">Feld 1<VisualStudio Path="C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\devenv.exe" Icon="VS.png">Visual Studio</VisualStudio>
    <Excel Path="C:\Program Files\Microsoft Office 15\root\office15\EXCEL.EXE" Icon="Excel.png">Excel</Excel>
  </Feld>
  <Home Icon="Folder.ico" Path="3">Home Place<Notepad Path="C:\Program Files\Notepad++\notepad++.exe" Icon="notepad.png">Notepad ++</Notepad>
    <JaTool Path="C:\Program Files (x86)\Tool7\javaw.exe" Argumente="-splash:splash.png -cp ./cl/cl.jar; -Dawt.useSystemAAFontSettings=on" Icon="JaTool.ico" RunPath="C:\Program Files (x86)\Tool7\bin\..">JaTool</JaTool>
  </Home>
</Programme>

Here is my VB-Code :

Option Strict On
Imports System.Xml
Imports System.IO
Imports System.Text
Imports System.Text.RegularExpressions
Public Class treeViewLoadXml
    Dim imgLst As New ImageList
    Dim vImgPath(-1) As String, iv As Int32 = 0
    Private Sub treeViewLoadXml_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        Load_XML()
    End Sub
    Public Sub Load_XML()
        Try
            ' Get Xml's file stream.
            imgLst.ImageSize = New Drawing.Size(30, 27)
            Dim vPath() As String = Split(Application.ExecutablePath, "\")
            vPath(vPath.Length - 1) = "XMLFile1.xml"
            Dim filepath As String = Join(vPath, "\")
            Dim _rstream As New FileStream(filepath, FileMode.Open)
            ' Load Xml document.
            '
            Dim dom As New XmlDocument()
            dom.Load(_rstream)
            _rstream.Close()
            ' Initialize treeView control.
            '
            TreeView1.BeginUpdate()
            TreeView1.Nodes.Clear()
            TreeView1.Nodes.Add(New TreeNode(dom.DocumentElement.Name))
            ' Populate the treeView with the dom nodes.
            '
            AddNode(dom.DocumentElement, TreeView1.Nodes(0))
            If CBool(iv) Then
                For i = 0 To iv - 1
                    imgLst.Images.Add(Image.FromFile(vImgPath(i)))
                Next
                TreeView1.ImageList = imgLst
            End If
            TreeView1.EndUpdate()
            'TreeView1.ExpandAll()
        Catch xmlEx As XmlException
            MessageBox.Show(xmlEx.Message)
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub
    Private Sub AddNode(ByVal inXmlNode As XmlNode, ByVal inTreeNode As TreeNode)
        Dim i As Integer
        If inXmlNode.HasChildNodes Then
            Dim nodeList As XmlNodeList
            nodeList = inXmlNode.ChildNodes
            i = 0
            While i <= nodeList.Count - 1
                Dim xNode As XmlNode = inXmlNode.ChildNodes(i)
                Dim imgIndex As Int32 = -1
                Dim SelimgIndex As Int32 = -1
                If xNode.Attributes IsNot Nothing Then
                    For Each att As XmlAttribute In xNode.Attributes
                        If att.Name = "Icon" Then
                            imgIndex = addImage(att.Value)
                            SelimgIndex = addImage(att.Value)
                            Exit For
                        End If
                    Next
                End If
                Dim tNode As New TreeNode(xNode.Name)
                Dim bIsTxt As Boolean = False
                If tNode.Text = "#text" Then
                    tNode.Text = xNode.Value
                    bIsTxt = True
                End If
                If imgIndex <> -1 Then
                    tNode.ImageIndex = imgIndex
                End If
                If SelimgIndex <> -1 Then
                    tNode.SelectedImageIndex = SelimgIndex
                End If
                If bIsTxt Then
                    'inTreeNode.Text += " " + tNode.Text '
                    inTreeNode.Text = tNode.Text
                Else
                    inTreeNode.Nodes.Add(tNode)
                    AddNode(xNode, tNode)
                End If
                i += 1
            End While
            If inXmlNode.Attributes IsNot Nothing AndAlso inXmlNode.Attributes("Path") IsNot Nothing Then
                inTreeNode.Name = inXmlNode.Attributes("Path").Value
            End If
            If inXmlNode.Attributes IsNot Nothing AndAlso inXmlNode.Attributes("Argumente") IsNot Nothing Then
                inTreeNode.Name = inXmlNode.Attributes("Argumente").Value
            End If
            If inXmlNode.Attributes IsNot Nothing AndAlso inXmlNode.Attributes("RunPath") IsNot Nothing Then
                inTreeNode.Name = inXmlNode.Attributes("RunPath").Value
            End If
        End If
    End Sub
    Function addImage(path As String) As Int32
        Dim i As Int32 = Array.IndexOf(vImgPath, path)
        If i = -1 AndAlso IO.File.Exists(path) Then
            ReDim Preserve vImgPath(iv)
            Me.vImgPath(iv) = path
            i = iv
            iv += 1
        End If
        Return i
    End Function
    Private Sub TreeView1_NodeMouseDoubleClick(sender As Object, e As System.Windows.Forms.TreeNodeMouseClickEventArgs) Handles TreeView1.NodeMouseDoubleClick
        Try
            Dim Path As String = TreeView1.SelectedNode.Name
            Dim Argumente As String = TreeView1.SelectedNode.Name
            Dim RunPath As String = TreeView1.SelectedNode.Name
            If IsNumeric(Path) Then
                Dim nAction As Int32 = Int32.Parse(Path)
                Select Case nAction
                    Case 1 'wenn was gemacht werden soll, wenn Path ist nur eine Zahl
                        ' do job for Path="1" ' 
                    Case 2
                        ' do job for Path="2" '
                    Case 3
                        ' do job for Path="3" '
                End Select
            Else
                Select Case e.Node.Text
                    Case "Visual Studio"
                        MsgBox("Visual Studio")
                        '...
                    Case "Excel"
                        MsgBox("Excel")
                        '...
                    Case "Notepad ++"
                        MsgBox("Notepad")
                        '...
                End Select
                If File.Exists(Path) Then
                    Process.Start(Path)
                    'Dim MyProcess As New Process()
                    'MyProcess.StartInfo.FileName = Path
                    'MyProcess.StartInfo.Arguments = Argumente '(optional)
                    'MyProcess.Start()
                End If
            End If
        Catch ex As Exception
            MsgBox("kein Programm gefunden")
        End Try
    End Sub
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim Path As String = TreeView1.SelectedNode.Name
        Dim Argumente As String = TreeView1.SelectedNode.Name
        Dim RunPath As String = TreeView1.SelectedNode.Name
        Label1.Text = Path
        Label2.Text = Argumente
        Label3.Text = RunPath
    End Sub
End Class

@Josh_4 Please, take a look to the answer at your first thread Here

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.