XmlHelper
获取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;
}获取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();
}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();
}
}- 获取节点的所有子节点,并用哈希表保存值
//获取节点的所有子节点,并用哈希表保存值
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的更多相关文章
- 使用XmlHelper添加节点C#代码
接着上一篇:http://keleyi.com/a/bjac/ttssua0f.htm在前篇文章中,给出了C# XML文件操作类XmlHelper的代码,以及使用该类的一个例子,即使用XmlHelpe ...
- (三)XmlHelper
[转]http://blog.csdn.net/u011866450/article/details/50373222 using System.Xml; using System.Data; nam ...
- XMLHelper.cs
http://yunpan.cn/Q7czcYTwE8qkc 提取码 545c using System; using System.Linq; using System.Xml.Linq; usi ...
- C#XmlHelper操作Xml文档的帮助类
using System.Xml; using System.Data; namespace DotNet.Utilities { /// <summary> /// Xml的操作公共类 ...
- 转XMLHelper
http://www.cnblogs.com/lixyvip/archive/2009/09/16/1567929.html using System; using System.Collection ...
- [XML] C# XmlHelper操作Xml文档的帮助类 (转载)
点击下载 XmlHelper.rar 主要功能如下所示 /// <summary> /// 类说明:XmlHelper /// 编 码 人:苏飞 /// 联系方式:361983679 // ...
- C# XML文件操作类XmlHelper
类的完整代码: using System;using System.Collections;using System.Xml; namespace Keleyi.Com.XmlDAL{public c ...
- XMLHelper 类
这个XMLHelper类中包括了XML文档的创建,文档节点和属性的读取,添加,修改,删除的方法功能的实现,有兴趣的朋友,可以进来看看,所有代码都在WebForm和WinForm中调试通过. 这是下面 ...
- [No0000DE]C# XmlHelper XML类型操作 类封装
using System; using System.Data; using System.IO; using System.Text; using System.Threading; using S ...
- XMLHelper类 源码(XML文档帮助类,静态方法,实现对XML文档的创建,及节点和属性的增、删、改、查)
以下是代码: using System; using System.Collections.Generic; using System.Linq; using System.Web; using Sy ...
随机推荐
- Metro-Ural119递推
Time limit: 0.5 second Memory limit: 64 MB Many of SKB Kontur programmers like to get to work by Met ...
- JS控制的几种页面跳转方式和传值
第一种:<script language="javascript" type="text/javascript">window.location.h ...
- Ubuntu .deb包安装方法
使用apt-get方法安装的软件,所有下载的deb包都缓存到了/var/cache/apt/archives目录下了,所以可以把常用的deb包备份出来,甚至做成ISO工具包.刻盘,以后安装Ubuntu ...
- Oracle 截取字符串
如下有一个创建函数的代码,是将一穿字符串按照逗号‘,’分割成若干段 create or replace function SplitStringByComma(aName in varchar2) r ...
- Linux服务器的那些性能参数指标
Linux服务器的那些性能参数指标 一个基于Linux操作系统的服务器运行的同时,也会表征出各种各样参数信息.通常来说运维人员.系统管理员会对这些数据会极为敏感,但是这些参数对于开发者来说也十分重要, ...
- ip封包
I P封包 從一直以來討論至今﹐我們都不斷地接觸到“封包”這個詞﹐相信您也很有興趣想知道這個“封包”究竟是個什麼樣的東東吧﹗下面就讓我們一起看看一個IP封包究竟包含了那些內容. 擷取IP封包 如果您的 ...
- VIM常用设置
批量替换: #:%s/source_pattern/target_pattern/g "My Custom Configuration filetype plugin indent on ...
- vnc连接kali 2.0 报错:A problem has occurred and the system can't recover.
kali版本: root@kali:~# uname -a Linux kali -kali1-amd64 # SMP Debian -7kali2 (--) x86_64 GNU/Linux 第一步 ...
- nignx 负载均衡的几种算法介绍
负载均衡,集群必须要掌握,下面介绍的负载均衡的几种算法. 1 .轮询,即所有的请求被一次分发的服务器上,每台服务器处理请求都相同,适合于计算机硬件相同. 2.加权轮询,高的服务器分发更多的请求 ...
- shell编程之变量
变量: 变量由字母.数字._ 组成,不能以数字开头 长度不能超过255个字符 在bash中,变量的默认类型是字符串类型 变量分类: 1.用户自定义变量:只在当前shell生效,是局部变量 定义方法: ...