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. 网易测试分享会——“一起打造你想要的QA团队”

    昨天(2016.11.30)参加了网易资深测试专家王晓明的测试分享会——“一起打造你想要的QA团队”,以下为笔者做的归纳总结. 重点 1.让测试更加容易做好.不容易测试的代码,不具有健壮性. 2.Ke ...

  2. What's the difference between <b> and <strong>, <i> and <em> in HTML/XHTML? When should you use each?

    ref:http://stackoverflow.com/questions/271743/whats-the-difference-between-b-and-strong-i-and-em The ...

  3. MVC的多表单

    中心思想就是在一个表单内不规定"action",在js里面用@Url.Axtion("视图层","控制器")方法来设置表单的传值. 控制器 ...

  4. informix(懒得通用)

    1.create view  444(...)  as select ...from... 2.insert into select.......union  select     不支持 请分开写 ...

  5. JDBC三层架构

    三层框架: 通常意义上的三层架构就是将整个业务应用划分为:表现层(UI).业务逻辑层(BLL).数据访问层(DAL).区分层次的目的即为了“高内聚,低耦合”的思想. 原理:1:数据访问层:主要是对原始 ...

  6. js的match()方法介绍

    定义和用法 match() 方法可在字符串内检索指定的值,或找到一个或多个正则表达式的匹配. 该方法类似 indexOf() 和 lastIndexOf(),但是它返回指定的值,而不是字符串的位置. ...

  7. xcode相关配置

    Xcode将全部供应配置文件(包括用户手动下载安装的和Xcode自动创建的Team Provisioning Profile)放在目录~/Library/MobileDevice/Provisioni ...

  8. gif图片加载问题

    之前从没想过,gif图片在网页中显示还会有问题,不过今天算是遇到了bug,问题是在vc嵌入的网页里面,有三个需要显示加载的动态图,刚开始在html中写好,在div向上滚动显示gif的时候就成了静态的. ...

  9. jQuery 学习笔记_01

    jQuery是一个简洁快速灵活的JavaScript框架,能让你在网页上简单的操作文档.处理事件.实现特效并为Web页面添加Ajax交互. 1 jQuery大多是基于 document 一个或多个元素 ...

  10. 利用Object.prototype.toString方法,实现比typeof更准确的type校验

    Object.prototype.toString方法返回对象的类型字符串,因此可以用来判断一个值的类型. 调用方法: Object.prototype.toString.call(value) 不同 ...