易截截图软件、单文件、免安装、纯绿色、仅160KB

将数组转化为XML数据

/* Author: 杨宇  yangyu@sina.cn */
/*
用法示例:
$cls_xml = new cls_xml();
if ($array){
 $cls_xml->array2xml($array);
 echo $cls_xml->getXml(); 
}else{
 echo '';
}
*/
class cls_xml{
        var $xml;
        public function array2xml($array,$encoding='gb2312'){
                $this->xml = '<?xml version="1.0" encoding="'.$encoding.'"?><list>';
                $this->xml.= $this->_array2xml($array).'</list>';
        }
        public function getXml(){
                return $this->xml;
        }
        public function _array2xml($array){
                $xml = '';
    foreach($array as $key => $val){
                        is_numeric($key)  &&  $key = "item id=\"$key\"";
                        $xml. = "<$key>";
                        $xml. = is_array($val) ? $this->_array2xml($val) : $this->_cdata($val);
                        list($key,) = explode(' ',$key);
 


相关文档:

c# 从XML读数据

C#
 DataSet ds = new DataSet();
ds.ReadXml(Server.MapPath("~/Config/User_yhlx_Jb.xml"));
DataView dv = ds.Tables[0].DefaultView;
//dv.RowFilter = "State=0";
this.DropDownList1.DataSource = dv;
this.DropDownList1.DataTextField = "text";
this ......

xml操作

     protected void Button1_Click(object sender, EventArgs e)
        {
            //为response(star)节点 和  Cabins(f) cabin节点分别添加个
      &nbs ......

c# XML序列化与反序列化

原先一直用BinaryFormatter来序列化挺好,可是最近发现在WinCE下是没有办法进行BinaryFormatter操作,很不爽,只能改成了BinaryWriter和BinaryReader来读写,突然想到能不能用XML来序列化?于是在网上查了些资料便写了些实践性代码,做些记录,避免以后忘记。
序列化对象
    public class People
  ......

初学XML(二) XML解析器

XML解析器的作用:为应用程序从XML文件中解析出所需要的数据。
下面通过一个例子,来了解,如何用XML解析器,来解析一个XML文件中的数据。
1、Types.xml(显示吉他的类别)
<?xml version="1.0" encoding="UTF-8"?>
<types>
<name>电吉他
<music>玩摇滚</music>
</name>
......

C#序列化与反序列化Xml,利用范型做通用化处理

public class yzzSerialize
{
private yzzSerialize()
{ }
private static yzzCache cache = new yzzCache();
public static T GetfromXml<T>(string xmlpath, T t)
{
using (FileStream fs = new FileStream(xmlpath, FileMode.Open, FileAcces ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号