file a.xml
codice:
<?xml version="1.0" encoding="utf-8" ?>
<nodo>
<figlio1>valore1</figlio1>
<figlio2>valore2</figlio2>
<figlio3>valore3</figlio3>
</nodo>
pagina a.aspx
codice:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="a.aspx.vb" Inherits="prove_a" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Pagina senza titolo</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="Button1" runat="server" Text="Button" />
<hr />
<asp:Label ID="Label1" runat="server" Text=""></asp:Label>
</div>
</form>
</body>
</html>
codice
codice:
Option Strict On
Partial Class prove_a
Inherits System.Web.UI.Page
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim xmlDoc As New XmlDocument()
'leggo il file xml
xmlDoc.Load(Server.MapPath("a.xml"))
'accedo alla radice del DOM
Dim xmlEl As XmlElement = xmlDoc.DocumentElement()
Dim nodi As XmlNodeList = xmlEl.ChildNodes()
'leggo i nodi: nome e valore
Me.Label1.Text = "" 'visualizzo i dati in una label
'memorizzo i dati nel dizionario come coppia nome-valore
Dim d As New Dictionary(Of String, String)
For Each nodo As XmlNode In nodi
Me.Label1.Text &= String.Format("{0}: {1}{2}", nodo.Name, nodo.FirstChild.Value, "
")
d.Add(nodo.Name, nodo.FirstChild.Value)
Next
End Sub
End Class