/// <summary> /// 鼗字典数据转换为Xml格式数据. /// </summary> /// <typeparam name="T">指字的数据类型</typeparam> /// <param name="dic">待转的数据字典.</param> /// <param name="nodeName">输出的主节点名称.</param> /// <returns></returns> public static string ToXml <T>(this Dictionary <string, T> dic, string nodeName) { StringBuilder sb = new StringBuilder(); try { if (!string.IsNullOrEmpty(nodeName)) { sb.Append("<" + nodeName + ">"); } foreach (KeyValuePair <string, T> temp in dic) { if (temp.Key != null && temp.Value != null) { sb.Append(Utils.ConvertXmlData(temp.Key, temp.Value.ToString())); } } if (!string.IsNullOrEmpty(nodeName)) { sb.Append("</" + nodeName + ">"); } } catch (Exception ex) { new ECFException(ex); } return(sb.ToString()); }
/// <summary> /// 鼗字典数据转换为Xml格式数据. /// </summary> /// <typeparam name="T">指字的数据类型</typeparam> /// <param name="table">待转的数据字典.</param> /// <param name="nodeName">输出的主节点名称.</param> /// <returns></returns> public static string ToXml <T>(this Hashtable table, string nodeName) { StringBuilder sb = new StringBuilder(); try { sb.Append("<" + nodeName + ">"); foreach (KeyValuePair <string, T> temp in table) { if (temp.Key != null && temp.Value != null) { sb.Append(Utils.ConvertXmlData(temp.Key, temp.Value.ToString())); } } sb.Append("</" + nodeName + ">"); } catch (Exception ex) { new ECFException(ex); } return(sb.ToString()); }