首页 > 代码库 > 读取xml文件(可执行文件根目录debug)
读取xml文件(可执行文件根目录debug)
xml文件格式如下
1 <?xml version="1.0" encoding="utf-8" ?>2 <root>3 <appKey>abcdefg</appKey>4 <appSecret>hijklmn</appSecret>5 <serverUrl>opqrst</serverUrl>6 <accessToken>uvwxyz</accessToken>7 </root>
读取格式如下,我是放在构造函数里面
先声明几个私有变量接受
private string SERVER_URL;private string accessToken;private string appKey;private string appSecret;
3 //判断可执行文件下有么有JD_API.xml文件,也就是debug目录下 4 if (File.Exists(Application.StartupPath + "\\JD_API.xml")) 5 { 6 XmlDocument xml = new XmlDocument(); 7 xml.Load(Application.StartupPath+"\\JD_API.xml");//加载xml文件 8 appKey = xml.SelectSingleNode("root/appKey").InnerText;//读取xml节点 9 appSecret = xml.SelectSingleNode("root/appSecret").InnerText;10 SERVER_URL = xml.SelectSingleNode("root/serverUrl").InnerText;11 accessToken = xml.SelectSingleNode("root/accessToken").InnerText;12 }
读取xml文件(可执行文件根目录debug)
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。