1. 获取XML节点的值(http服务使用xml传输数据,节点名称唯一)

        /// <summary>
    /// 获取xml节点的值
    /// </summary>
    /// <param name="xml">xml字符串</param>
    /// <param name="xmlnode">节点名</param>
    /// <returns>节点值</returns>
    public static string GetXmlNodeValue(string xml, string xmlnode)
    {
    XmlDocument xmlDoc = new XmlDocument();
    xmlDoc.LoadXml(xml);
    string val = XDocument.Load(new StringReader(xml)).Descendants(xmlnode).First().Value;
    return val;
    }
  2. 获取XML节点的内容(http服务使用xml传输数据,节点名称唯一)

    /// <summary>
    /// 获取xml节点的内容
    /// </summary>
    /// <param name="xml">xml字符串</param>
    /// <param name="xmlnode">节点名</param>
    /// <returns>节点值</returns>
    public static string GetXmlNodeNode(string xml, string xmlnode)
    {
    XmlDocument xmlDoc = new XmlDocument();
    xmlDoc.LoadXml(xml);
    object val = XDocument.Load(new StringReader(xml)).Descendants(xmlnode).First();
    return val.ToString();
    }
  3. XML与DataSet互转(xml文件与DataTable格式一致)

       private string ConvertDataTableToXML(DataTable xmlDS)
    {
    MemoryStream stream = null;
    XmlTextWriter writer = null;
    try
    {
    stream = new MemoryStream();
    writer = new XmlTextWriter(stream, Encoding.Default);
    xmlDS.WriteXml(writer);
    int count = (int)stream.Length;
    byte[] arr = new byte[count];
    stream.Seek(, SeekOrigin.Begin);
    stream.Read(arr, , count);
    UTF8Encoding utf = new UTF8Encoding();
    return utf.GetString(arr).Trim();
    }
    catch
    {
    return String.Empty;
    }
    finally
    {
    if (writer != null) writer.Close();
    }
    }
    private DataSet ConvertXMLToDataSet(string xmlData)
    {
    StringReader stream = null;
    XmlTextReader reader = null;
    try
    {
    DataSet xmlDS = new DataSet();
    stream = new StringReader(xmlData);
    reader = new XmlTextReader(stream);
    xmlDS.ReadXml(reader);
    return xmlDS;
    }
    catch (Exception ex)
    {
    string strTest = ex.Message;
    return null;
    }
    finally
    {
    if (reader != null)
    reader.Close();
    }
    }
  4. 获取节点的所有子节点,并用哈希表保存值
//获取节点的所有子节点,并用哈希表保存值
private Hashtable GetChildNodesHT(XmlDocument xmlDoc, string strNodeName)
{
Hashtable ht = new Hashtable();
XmlNodeList xnThis = xmlDoc.GetElementsByTagName(strNodeName);
try
{
XmlNodeList childNodes = xnThis[].ChildNodes;
foreach (XmlNode xn in childNodes)
{
if (ht.ContainsKey(xn.Name) == false)
{
ht[xn.Name] = xn.InnerText;
}
}
}
catch { }
return ht;
}

XmlHelper的更多相关文章

  1. 使用XmlHelper添加节点C#代码

    接着上一篇:http://keleyi.com/a/bjac/ttssua0f.htm在前篇文章中,给出了C# XML文件操作类XmlHelper的代码,以及使用该类的一个例子,即使用XmlHelpe ...

  2. (三)XmlHelper

    [转]http://blog.csdn.net/u011866450/article/details/50373222 using System.Xml; using System.Data; nam ...

  3. XMLHelper.cs

    http://yunpan.cn/Q7czcYTwE8qkc  提取码 545c using System; using System.Linq; using System.Xml.Linq; usi ...

  4. C#XmlHelper操作Xml文档的帮助类

    using System.Xml; using System.Data; namespace DotNet.Utilities { /// <summary> /// Xml的操作公共类 ...

  5. 转XMLHelper

    http://www.cnblogs.com/lixyvip/archive/2009/09/16/1567929.html using System; using System.Collection ...

  6. [XML] C# XmlHelper操作Xml文档的帮助类 (转载)

    点击下载 XmlHelper.rar 主要功能如下所示 /// <summary> /// 类说明:XmlHelper /// 编 码 人:苏飞 /// 联系方式:361983679 // ...

  7. C# XML文件操作类XmlHelper

    类的完整代码: using System;using System.Collections;using System.Xml; namespace Keleyi.Com.XmlDAL{public c ...

  8. XMLHelper 类

     这个XMLHelper类中包括了XML文档的创建,文档节点和属性的读取,添加,修改,删除的方法功能的实现,有兴趣的朋友,可以进来看看,所有代码都在WebForm和WinForm中调试通过. 这是下面 ...

  9. [No0000DE]C# XmlHelper XML类型操作 类封装

    using System; using System.Data; using System.IO; using System.Text; using System.Threading; using S ...

  10. XMLHelper类 源码(XML文档帮助类,静态方法,实现对XML文档的创建,及节点和属性的增、删、改、查)

    以下是代码: using System; using System.Collections.Generic; using System.Linq; using System.Web; using Sy ...

随机推荐

  1. Tomcat去除项目名称和端口号,直接使用ip地址访问项目的方法

    网站开发过程中,一般的工程访问路径是 http://112.74.51.37/projectName如何设置成http://112.74.51.37/ 解决方法: 首先,进入tomcat的安装目录下的 ...

  2. html5的新特性——拖放API

    在HTML5之前只能使用鼠标事件模拟出"拖放"效果:HTML5专门为拖放提供了7个事件句柄.  被拖动的源对象可以触发的事件: (1)ondragstart:源对象开始被拖动 (2 ...

  3. jquery中focus()函数实现当对象获得焦点后自动把光标移到内容最后

    代码如下: setFocus=function(id){ var t=$("#"+id).val(); $("#"+id).val(""). ...

  4. arguments的理解

    (function(){ return typeof arguments; })(); 无聊的时候看看网上的面试题.个人认为通过面试题可以对某个知识点能够更加认识,踩过坑才会明白坑是有多大.代码中经常 ...

  5. VB默认属性、动态数组、Range对象的默认属性的一点不成熟的想法

    1.默认属性 VB6.0有默认属性的特性.当没有给对象指定具体的属性时,"默认属性"是VB6.0将使用的属性.在某些情形下,省略常用属性名,使代码更为精简. 因为CommandBu ...

  6. Xcode 7免证书真机调试

    在Xcode 7中,苹果改变了自己在许可权限上的策略,此前Xcode只开放给注册开发者下载,但Xcode 7改变了这种惯有的做法,无需注册开发者账号,仅使用普通的Apple ID就能下载和上手体验.此 ...

  7. 解决yum update失败

    1.yum update .yum clean.yum install操作提示 Loaded plugins: fastestmirror, langpacks Loading mirror spee ...

  8. [转]抓取安卓APP内接口的方法--Charles

    http://blog.csdn.net/yyh352091626/article/details/52759294

  9. 输入事件驱动---evdev_handler的大致实现流程(修整版)

    一.input输入子系统框架 下 图是input输入子系统框架,输入子系统由输入子系统核心层(input core),驱动层和事件处理层(Event Handler)三部分组成.一个输入事件,比如滑动 ...

  10. 20161117__Z

    1.cclplus: error: unrecognized command line option "-std=gnu++11" http://www.gowhich.com/b ...