1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| Public Function GetXMLSetting(ByVal sPath As String, ByVal defaultvalue As Object, ByVal ParamArray sNode() As String) As String
' Lit un paramètre dans le fichier XML s'il existe
' si defaultValue est renseigné, la valeur est inscrite dans le fichier
' si le paramètre n'existe pas dans le fichier et si default value n'est pas renseigné, retourne nothing
Try
Dim xcfg As New Xmlconfig(sPath, False)
' reconstitution de la chaîne de noeuds
Dim sSetting As String = Nothing
Dim node1 As ConfigSetting = xcfg.Settings(sNode(0))
For i = 0 To sNode.Count - 2
sSetting &= sNode(i) & "/"
Next
sSetting &= sNode(sNode.Count - 1)
If xcfg.Settings(sSetting).Value = String.Empty AndAlso Not defaultvalue Is Nothing Then
' si la valeur n'existe pas dans le fichier et si defaultvalue n'est pas "Nothing", alors on écrit la valeur dans le fichier XML
xcfg.Settings(sSetting).Value = defaultvalue
xcfg.Save(sPath)
End If
GetXMLSetting = xcfg.Settings(sSetting).Value 'on retourne la valeur du fichier XML
xcfg.Dispose()
Catch ex As Exception
MessageBox.Show(ex.ToString, "GetXMLSetting")
End Try |