zoukankan      html  css  js  c++  java
  • 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;

  • 相关阅读:
    sql
    Java 反射
    Java 泛型
    Java 数组小记
    Java 实现二叉树
    Maven的环境配置
    用于解决easui 保存时候,前台传参是空字符串不null
    SpringMVC
    SpringMVC
    解决MySql varchar类型的数字排序
  • 原文地址:https://www.cnblogs.com/1175429393wljblog/p/10219540.html
Copyright © 2011-2022 走看看