XmlDocument.Load(url) 的使用

版权声明:本文为博主原创文章,博主的辛苦付出希望大家尊重,未经博主允许不得抄袭,转载请标明出处。 https://blog.csdn.net/LongtengGensSupreme/article/details/85773555

远程

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;

猜你喜欢

转载自blog.csdn.net/LongtengGensSupreme/article/details/85773555