Lettura XML !!






Imports System
Imports System.IO
Imports System.Xml



Public Class Form5

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim ws, pi, dc, cc, ac, et, el, xd As Integer
' Read a document

Dim textReader As XmlTextReader = New XmlTextReader("\scheda di memoria\Acqua\Codici.xml")
' Read until end of file

While textReader.Read()
Dim nType As XmlNodeType = textReader.NodeType
' If node type us a declaration

If nType = XmlNodeType.XmlDeclaration Then
TextBox1.Text = TextBox1.Text & vbCrLf & ("Declaration:" + textReader.Name.ToString())
xd = xd + 1
End If
' if node type is a comment

If nType = XmlNodeType.Comment Then
TextBox1.Text = TextBox1.Text & vbCrLf & ("Comment:" + textReader.Name.ToString())
cc = cc + 1
End If
' if node type us an attribute

If nType = XmlNodeType.Attribute Then
TextBox1.Text = TextBox1.Text & vbCrLf & ("Attribute:" + textReader.Name.ToString())
ac = ac + 1
End If
' if node type is an element

If nType = XmlNodeType.Element Then
TextBox1.Text = TextBox1.Text & vbCrLf & ("Element:" + textReader.Name.ToString())
el = el + 1
End If
' if node type is an entity

If nType = XmlNodeType.Entity Then
TextBox1.Text = TextBox1.Text & vbCrLf & ("Entity:" + textReader.Name.ToString())
et = et + 1
End If
' if node type is a Process Instruction

If nType = XmlNodeType.Entity Then
TextBox1.Text = TextBox1.Text & vbCrLf & ("Entity:" + textReader.Name.ToString())
pi = pi + 1
End If
' if node type a document

If nType = XmlNodeType.DocumentType Then
TextBox1.Text = TextBox1.Text & vbCrLf & ("Document:" + textReader.Name.ToString())
dc = dc + 1
End If
' if node type is white space

If nType = XmlNodeType.Whitespace Then
TextBox1.Text = TextBox1.Text & vbCrLf & ("WhiteSpace:" + textReader.Name.ToString())
ws = ws + 1
End If
End While
TextBox1.Text = TextBox1.Text & vbCrLf & ("Total Comments:" + cc.ToString())
TextBox1.Text = TextBox1.Text & vbCrLf & ("Total Attributes:" + ac.ToString())
TextBox1.Text = TextBox1.Text & vbCrLf & ("Total Elements:" + el.ToString())
TextBox1.Text = TextBox1.Text & vbCrLf & ("Total Entity:" + et.ToString())
TextBox1.Text = TextBox1.Text & vbCrLf & ("Total Process Instructions:" + pi.ToString())
TextBox1.Text = TextBox1.Text & vbCrLf & ("Total Declaration:" + xd.ToString())
TextBox1.Text = TextBox1.Text & vbCrLf & ("Total DocumentType:" + dc.ToString())
TextBox1.Text = TextBox1.Text & vbCrLf & ("Total WhiteSpaces:" + ws.ToString())


End Sub
End Class










( letturaxml.html )- by Paolo Puglisi - Modifica del 17/12/2023