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>

  • 相关阅读:
    solr 5.3.1安装配置
    STS 设置代码注释模板
    visual studio 设置代码注释模板
    JAXBContext处理CDATA
    用STS和Maven的方式创建一个JavaWeb项目
    .NET跨平台实践:用C#开发Linux守护进程-Daemon
    不装mono,你的.NET程序照样可以在Linux上运行!
    Tomcat关闭日志输出
    使用git pull文件时和本地文件冲突怎么办?
    Linux命令-进程后台执行:nohup(就是不挂起的意思)
  • 原文地址:https://www.cnblogs.com/googlegis/p/2978852.html
Copyright © 2011-2022 走看看