Torna al Thread

[CODE] 'funzione che aggiorna il valore dell'attributo attr del nodo di nome nodo Public Function updateNodo(ByVal padre As String, ByVal nodo As String, ByVal attr As String, ByVal newval As String) As String Dim reader As System.Xml.XmlTextReader Dim doc As XmlDocument Dim node, a, b As XmlNode Try Dim modified As Boolean = False doc = New XmlDocument doc.Load(path) Dim root As XmlElement = doc.DocumentElement node = root.SelectSingleNode(nodo) Dim str As String For Each a In root.ChildNodes If a.Name.Equals(padre) Then node = a For Each b In node.ChildNodes If b.Name.Equals(nodo) Then b.Attributes(attr).Value = newval modified = True End If Next End If Next If modified Then doc.Save("temp.xml") System.IO.File.Copy("temp.xml", path, True) Return "OK" Else 'non salvo x' non c'è stata nessuna modifica Return "Nodo non trovato" End If Catch ex As Exception If String.Compare(ex.Message, "Elemento di primo livello mancante.") = 0 Then Return "File xml vuoto" Else Return ex.Message End If Finally doc = Nothing End Try End Function [/CODE]
Copyright © dotNetHell.it 2002-2024
Running on Windows Server 2008 R2 Standard, SQL Server 2012 & ASP.NET 3.5