XmlDocument.Load(url) 本地和http远程

XmlDocument.Load(url) 的使用

 

远程

string path = @"http://localhost:8080/Source/XMLConfig.xml";//从http远程加载xml文档
XmlDocument doc = new XmlDocument();
doc.Load(path);
XmlNode httpservice = doc.SelectSingleNode("configuration");

 本地

如果是 xml 本地文件,转换起来比较方便,可以采用这种方法:

string path = AppDomain.CurrentDomain.BaseDirectory;
path = Path.Combine(path, "XMLConfig.xml");
XmlDocument doc = new XmlDocument();
//path = @"http://localhost:8080/Source/XMLConfig.xml";
doc.Load(path);
XmlNode httpservice = doc.SelectSingleNode("configuration");
XmlNodeList httpserviceNodes = httpservice.ChildNodes;

 

还有一种是远程加载字符串

XmlDocument doc = new XmlDocument();
doc.LoadXml(new WebClient().DownloadString(@"http://localhost:8080/Source/XMLConfig.xml"));
XmlNode httpservice = doc.SelectSingleNode("configuration");
XmlNodeList httpserviceNodes = httpservice.ChildNodes;

posted @ 2019-01-04 14:08  龙骑科技  阅读(850)  评论(0编辑  收藏  举报