| 

.NET C# Java Javascript Exception

1
Wie kann man die Daten auslesen im XML!


XML:
<?xml version="1.0" encoding="utf-8"?>
<STEUERDATEI xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<KOPF VERSION="20180529_0948" STYP="2" BTYP="NE" BTZ="NEUTEIL">
<BEZEICHNUNG BZ="GP7000_FAIRING" SANR="1DY72390" SN="BTB71634" SNT="S" EWIS="85F8761904" ISSUEP="" />
<ROHTEIL RSANR="" RSN="" LNUM="" MSOURCE="NEIN" />
<MC610 NCP="1DY72390YL007" NCPV="3" NCD="1DY72390YL007" MCP="JA" PK="NEIN" TKAL="JA" BKAL="JA" TKALM="NEIN" BKALM="NEIN" />
<CMM MPH="1DY72390L0170" MPHV="6" MPS="" MPSV="1" DDAT="JA" PKCMM="NEIN" />
<AUSKNACKEN NCA1="" NCA1V="" NCA2="" NCA2V="" FHMA1="" FHMA2="" />
<EINKLEBEN NCE1="" NCE1V="" NCE2="" NCE2V="" FHME1="" FHME2="" />
<ENTGRATEN NCB1="" NCB1V="" NCB2="" NCB2V="" FHMB1="" FHMB2="" />
<ERODIEREN NCF1="" NCF1V="" NCF2="" NCF2V="" FHMF1="" FHMF2="" />
<KENNZEICHNEN NCK1="" NCK1V="" NCK2="" NCK2V="" FHMK1="" FHMK2="" />
<STRAHLEN NCS1="" NCT1V="" NCT2="" NCT2V="" FHMT1="" FHMT2="" />
<WASCHEN NCW1="" NCW1V="" NCW2="" NCW2V="" FHMW1="" FHMW2="" />
<BESCHICHTEN NCB1="" NCB1V="" NCB2="" NCB2V="" FHMB1="" FHMB2="" />
<LOETEN NCL1="" NCL1V="" NCL2="" NCL2V="" FHML1="" FHML2="" />
<ADDITIONAL MC1="" MC2="" MC3="" MC4="" MC5="" />
<SHUTTLES>
<SHUTTLE SH="1DY72348F100">
<LIEFERANTEN>
<LIEFERANT LNUM="" RSANR="" KMCD="D1DY72390YL007" KMCV="3" ASTD="" ASTV="" />
</LIEFERANTEN>
</SHUTTLE>
</SHUTTLES>
</KOPF>
<KONTUREN>
<KONTUR KNR="0" KBAZ="NEUTEIL">
<KONTURKOPF>
<KONTTYP KTYP="BASIS" KBAS="NEIN" BASISK="" BASISG="" BASISS="" />
<KONTBEZ BZK="BASIS_G54" BA="SERIE" />
<KMC610 AVO="50" SH="1DY72348F100" />
<KCMM AVOC="0170" AVOS="" FHMC="1DY72310P001" FHMS="1GN32204P002" MPHK="LM" MPSK="" MPNH="" MPNS="" MPNN="1" FAM="JA" GUAC="JA" GUAS="NEIN" />
<KORREKTUR KCMM="NEIN" KDAT="" KMC="KMC_YL007_0" EMESS="MC610" EMSH="NEIN" />
<GEOMETRIE WGEO="WGEO_BAS_YL007_0" PGEO="PGEO_BAS_YL007_0" />
<ADDITIONAL MCK="" />
</KONTURKOPF>
<OPERATIONEN>
<OPERATION ONR="1" OTYP="C" OART="" OBAS="" OBAZ="NEUTEIL" TECS="NEIN" TEC="TEC_9000_YL007_0_1" MC1OP="" MC2OP="" REIHENFOLGE="1" />
</OPERATIONEN>
</KONTUR>


CODE:
'Imports System.Windows.Forms.ListViewItem
Imports System.Xml

Public Class Form1



Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim XMLReadWrite As New List(Of XmlTreeView)
' XML-Datei im TreeView anzeigen
Me.TreeView1.Nodes.Clear()
Me.TreeView2.Nodes.Clear()
XmlTreeView.LoadFromXml("C:\Users\Anwender\Documents\Visual Studio 2015\Projects\XMLReaderErowaPL\Beispiele\1DY72390_BTB71634_MNA.xml", Me.TreeView1)

' TreeView-Inhalt als XML-Datei speichern
XmlTreeView.SaveToXml("C:\Users\Anwender\Documents\Visual Studio 2015\Projects\XMLReaderErowaPL\Beispiele\test2.xml", Me.TreeView1)

End Sub

Private Sub TreeView1_AfterSelect(sender As Object, e As TreeViewEventArgs) Handles TreeView1.AfterSelect

End Sub
Private Sub TreeView2_AfterSelect(sender As Object, e As TreeViewEventArgs) Handles TreeView2.AfterSelect

End Sub
Private Sub TreeView1_NodeMouseDoubleClick(ByVal sender As Object, ByVal e As TreeNodeMouseClickEventArgs) Handles TreeView1.NodeMouseDoubleClick
Dim path = TryCast(TreeView1.SelectedNode, MyTreeNode)?.Path
If path IsNot Nothing Then Process.Start(path)
End Sub


End Class

Public Class XmlTreeView
' XML-Datei auslesen und die entsprechenden
' Nodes-Objekte im TreeView-Control erstellen
Public Shared Sub LoadFromXml(ByVal FileName As String, ByVal TheTreeView As TreeView)
Dim xDoc As New XmlDocument
xDoc.Load(FileName)
FillTreeView(TheTreeView.Nodes, xDoc.DocumentElement)
End Sub

Private Shared Sub FillTreeView(ByVal CurrentNodes As TreeNodeCollection,
ByVal xNode As XmlNode)

For Each xChild As XmlNode In xNode.ChildNodes
If xChild.Name <> "BZ" Then
FillTreeView(CurrentNodes.Add(xChild.Name).Nodes, xChild)
'#### Daten auslesen.... !!!!!!
Else
' CurrentNodes.Add(xChild.InnerText)
'CurrentNodes.Add(New MyTreeNode With {.Text = xChild.InnerText, .Path = xChild.Attributes("Path")?.Value})
CurrentNodes.Add(xChild.InnerText)
End If

Next
'comboBox1.Items.Add(nodeVorname.InnerText + " " + nodeNachname.InnerText + "\n");

End Sub




' TreeView-Inhalt (Nodes-Objekte) als XML-Datei speichern
Public Shared Sub SaveToXml(ByVal FileName As String, ByVal TheTreeView As TreeView)
Dim xDoc As New XmlDocument
xDoc.LoadXml("<Nodes></Nodes>")
SaveNodes(xDoc.DocumentElement, TheTreeView.Nodes)
xDoc.Save(FileName)
End Sub

Private Shared Sub SaveNodes(ByVal xNode As XmlNode, ByVal CurrentNodes As TreeNodeCollection)
For Each tn As TreeNode In CurrentNodes
Debug.WriteLine(tn.Text)
SaveNodes(xNode.AppendChild(xNode.OwnerDocument.CreateElement(tn.Text)), tn.Nodes)
Next
End Sub
End Class

Public Class MyTreeNode
Inherits TreeNode
Public Property Path As String
End Class


Gruss
Thomas Meier
14.08.2018
tsmeier 51 1 3
Ich verstehe deine Frage nicht ganz. Soweit ich das sehe, macht der Code doch das was du willst. Du müsstest dein Problem schon genauer beschreiben.
luedi 16.08.2018
1 Antwort
0
Falls es um das Auslesen der Attribute geht, dann hilft die Methode
GetAttribute("<AttributeName>")
auf dem gefundenen Node (Klasse XmlNode)

Vielleicht hilft dieser Artikel Ihnen beim Parsen des XML im MSDN-Forum.
21.08.2018
edvservice 1,4k 1 6

Stelle deine --Frage jetzt!