| |
VB.NET - Ein- und Umsteigeralle Attribute von ausgewählten XML-Knoten anzeigen/nutzen | | | Autor: joshi123 | Datum: 04.12.17 22:50 |
| Hallo,
leider habe ich im Forum nicht das richtige gefunden, bzw. konnte mit den Threads dann nichts anfangen um mein Problem zu lösen ;-|
Ich habe das Problem, dass mein VB-Code nicht alle Attribute von meiner XML ausliest.
Hier erst mal die Codes :
XML :
<?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> Die XML wird soweit gelesen, dass jeder Knoten sein Icon bekommt ("Icon" welches als Attribut angegeben ist) und auch der Pfad (Path) zum starten des Programms wird gelesen. Jedoch werden die weiteren Attribute ("Argumente" und "RunPath") nicht mit eingelesen und können somit auch nicht von mir verwendet werden.
Aktuell über den Button1 habe ich es versucht, die Attribute erst einmal einfach nur in Labels anzuzeigen. Nur wird immer nur ein und das gleiche Attribut angezeigt. Eine Fehlermeldung oder ähnliches erhalte ich aber nicht.
Ich komme einfach nicht weiter und hoffe das ihr mir hier weiterhelfen könnt!?!? | |
Re: alle Attribute von ausgewählten XML-Knoten anzeigen/nutzen | | | Autor: joshi123 | Datum: 04.12.17 22:52 |
| Hier noch der VB-Code (Teil-1) :
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 | |
Re: alle Attribute von ausgewählten XML-Knoten anzeigen/nutzen | | | Autor: joshi123 | Datum: 04.12.17 22:53 |
| Hier noch der VB-Code (Teil-2) :
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
'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 | |
| Sie sind nicht angemeldet! Um auf diesen Beitrag zu antworten oder neue Beiträge schreiben zu können, müssen Sie sich zunächst anmelden.
Einloggen | Neu registrieren |
|
|
vb@rchiv CD Vol.6 vb@rchiv Vol.6
Geballtes Wissen aus mehr als 8 Jahren vb@rchiv!
Online-Update-Funktion Entwickler-Vollversionen u.v.m.Jetzt zugreifen Tipp des Monats sevAniGif (VB/VBA)
Anzeigen von animierten GIF-Dateien
Ab sofort lassen sich auch unter VB6 und VBA (Access ab Version 2000) animierte GIF-Grafiken anzeigen und abspielen, die entweder lokal auf dem System oder auf einem Webserver gespeichert sind. Weitere Infos
|
|
|
Copyright ©2000-2024 vb@rchiv Dieter Otter Alle Rechte vorbehalten.
Microsoft, Windows und Visual Basic sind entweder eingetragene Marken oder Marken der Microsoft Corporation in den USA und/oder anderen Ländern. Weitere auf dieser Homepage aufgeführten Produkt- und Firmennamen können geschützte Marken ihrer jeweiligen Inhaber sein.
Diese Seiten wurden optimiert für eine Bildschirmauflösung von mind. 1280x1024 Pixel
|
|