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>

  • 相关阅读:
    Oracle创建表空间、创建用户以及授权
    Oracle数据库安装图文操作步骤
    Oracle 11g数据库详细安装步骤图解
    Java 开发环境配置--eclipse工具进行java开发
    ExtJs常用布局--layout详解(含实例)
    HTTPS-HTTPS原理
    JavaScript: JavaScript的简介和入门代码演示
    HTML: 仿写一个财经类静态的网页
    CSS:仿写博客园写一个静态网页
    CSS:CSS定位和浮动
  • 原文地址:https://www.cnblogs.com/googlegis/p/2978852.html
Copyright © 2011-2022 走看看