Autor Tema: Usar XML como un archivo INI  (Leído 2470 veces)

0 Usuarios y 1 Visitante están viendo este tema.

softmania

  • Bytes
  • *
  • Mensajes: 35
  • Reputación: +4/-0
    • Ver Perfil
Usar XML como un archivo INI
« en: Octubre 27, 2013, 02:29:02 am »
Hola, como lo dice el título una forma de usar XML para guardar configuración.

Código: (VB) [Seleccionar]
  Public Function LeerConfig(ByVal sNombre As String) As String
        Dim sReturn As String = String.Empty
        Dim dsConfig As New DataSet
        If System.IO.File.Exists(Application.StartupPath & "\config.xml") Then
            dsConfig.ReadXml(Application.StartupPath & "\config.xml")
        Else
            dsConfig.Tables.Add("Configuracion")
            dsConfig.Tables(0).Columns.Add("Nombre", GetType(String))
            dsConfig.Tables(0).Columns.Add("Valor", GetType(String))
        End If

        Dim dr() As DataRow = dsConfig.Tables("Configuracion").Select("Nombre = '" & sNombre & "'")
        If dr.Length = 1 Then sReturn = dr(0)("Valor").ToString

        Return sReturn
    End Function

    Public Sub GuadarConfig(ByVal sNombre As String, ByVal sValor As String)
        Dim dsConfig As New DataSet
        If System.IO.File.Exists(Application.StartupPath & "\config.xml") Then
            dsConfig.ReadXml(Application.StartupPath & "\config.xml")
        Else

            dsConfig.Tables.Add("Configuracion")
            dsConfig.Tables(0).Columns.Add("Nombre", GetType(String))
            dsConfig.Tables(0).Columns.Add("Valor", GetType(String))
        End If

        Dim dr() As DataRow = dsConfig.Tables(0).Select("Nombre = '" & sNombre & "'")
        If dr.Length = 1 Then
            dr(0)("Valor") = sValor
        Else
            Dim drConfig As DataRow = dsConfig.Tables("Configuracion").NewRow
            drConfig("Nombre") = sNombre
            drConfig("Valor") = sValor
            dsConfig.Tables("Configuracion").Rows.Add(drConfig)
        End If
        dsConfig.WriteXml(Application.StartupPath & "\config.xml")
    End Sub

SALU2
Solo se que no se nada!!! ;) By Sócrates

E N T E R

  • Petabyte
  • ******
  • Mensajes: 1062
  • Reputación: +57/-13
  • www.enterpy.com
    • Ver Perfil
    • www.enterpy.com
Re:Usar XML como un archivo INI
« Respuesta #1 en: Octubre 27, 2013, 02:43:38 pm »
Interesante gracias por el aporte.
CIBER GOOGLE - CONCEPCIÓN PARAGUAY
www.enterpy.com
Primera regla de la programacion, para que vas a hacerlo complicado si lo puedes hacer sencillo