zoukankan      html  css  js  c++  java
  • vb.net 读取XML配置文件

    在WinCE中不能使用相对路径,必须获得配置文件的绝对路径
    WinCE中不支持System.IO.Directory.GetCurrentDirectory()
    Dim curDir As String
            curDir = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase)
            Dim strFileName As String = curDir + "\config.xml"
            Dim fileInfo As New IO.FileInfo(strFileName)
            Dim xmlReader As System.Xml.XmlDocument
            xmlReader = New Xml.XmlDocument
            Dim nodeList As Xml.XmlNodeList
            If Not fileInfo.Exists Then
                MessageBox.Show(strFileName + " does not exist")
            Else
                xmlReader.Load(strFileName)
                nodeList = xmlReader.GetElementsByTagName("SystemName")
                MessageBox.Show(nodeList(0).Attributes(0).Value.ToString)
            End If
    ---------------------------------------------------------------------------------------------------------------------------------
    Dim strFileName As String = "\Config.xml"
            Dim strFileFullPath As String = Directory.GetCurrentDirectory() + strFileName
            Dim strFile As FileInfo = New FileInfo(strFileFullPath)
            If strFile.Exists Then
                Console.WriteLine(strFileName + " Exists !")
            Else
                Console.WriteLine(strFileName + " Not Exists !")
            End If
            Dim xmlReader As Xml.XmlDocument = New Xml.XmlDocument
            xmlReader.Load(strFileFullPath)
            Dim root As Xml.XmlNode = xmlReader.DocumentElement
            Console.WriteLine(" Root = " + root.Name)
            Console.WriteLine(" Root ChildNotes is {0:D}", root.ChildNodes(1).Attributes(0).Value)
            root.ChildNodes(1).Attributes(0).Value = "123456789"
            xmlReader.Save(strFileFullPath)
    配置文件config.xml和程序放在同一个目录下,具体数据如下:
    <DMConfig>
    <TSServer value="abcdefg" />
    <SystemName value="444444444444444" />
    <LogsPath value="2222222222222222" />
    <USBStickName value="33333333333333" />
    <USBSleepTimer value="25" />
    <IntroFilePath value="fffffffffffffff" />
    <AppFilePath value="ddddddddddddddd" />
    </DMConfig>

  • 相关阅读:
    .net core 经典面试题
    面试常问概念类问题
    常见 .net 面试题目
    Linux 最常用150个命令汇总
    .net core 国际化(web通用版)
    vim 命令合集
    解决Mariadb安装时的Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-install-qenllaxj/mysqlclient/报错
    正则表达式
    python中的JWT
    chapter2.3、react高阶组件,装饰器
  • 原文地址:https://www.cnblogs.com/googlegis/p/2978852.html
Copyright © 2011-2022 走看看