VB.NET读取保存项目中相对路径的XML

XML实际路径:E:\Project\eip\WebRoot\PowerEIPApplication\OnlienQuery\aul.xml
XML内容:
?<?xml version="1.0" encoding="utf-8"?>
<base>
  <shopId>10000001</shopId>
</base>

.VB代码
Imports System.Xml
Partial Public Class Query_Page
    Inherits System.Web.UI.Page

    Public strToExcel As String = "none"
    Public fileContents As String
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        
        Dim filename As String
        Dim curDir As String = System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase    '运行文件的当前相对目录     '"\"

        curDir = curDir.Substring(curDir.IndexOf("E:"), curDir.LastIndexOf(".") - 8)
        filename = curDir & "/aul.xml"
        filename = filename.Replace(".", "/").Replace("aul/xml", "aul.xml").Replace("/WebRoot/bin/Status", "")
        'Response.Write(filename)
        Dim doc As XmlDocument = New XmlDocument()
        doc.Load(filename)

        Dim root As XmlNode = doc.DocumentElement
        Dim shopId As XmlNode = root.SelectSingleNode("//base/shopId")
        Response.Write(shopId.InnerText) '读取节点值
        shopId.InnerText = "10000001" '设置节点值
        doc.Save(filename) '保存XML

    End Sub

End Class


posted @ 2016-07-29 14:08  离。  阅读(28)  评论(0编辑  收藏  举报