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

XML创建、读、写操作

Create:
int nFQ;
   XmlDocument doc = new XmlDocument();
   XmlAttribute
newAtt;
   //定义XML文档头文件
   XmlDeclaration dec =
doc.CreateXmlDeclaration("1.0",null,null);
   doc.AppendChild(dec);
   XmlElement
docRoot = doc.CreateElement("Orders");
   doc.AppendChild(docRoot);
   for(int i=0;i<12;i++)
   {
    XmlNode Order =
doc.CreateElement("Order");
    newAtt =
doc.CreateAttribute("Quantity");
    nFQ = 10*i +i;
    newAtt.Value
= nFQ.ToString();
    Order.Attributes.Append(newAtt);
    docRoot.AppendChild(Order);
   }
   
   //
保存XML文档
   string strPath = Server.MapPath("OutDocument.XML");
   doc.Save(strPath); 
Read:
一:   
// 创建XmlDocument类的实例
   XmlDocument doc = new XmlDocument();
   ArrayList
NodeValues = new ArrayList();
   // 把people.xml文件读入内存,形成一个DOM结构
   doc.Load(
Server.MapPath("people.xml") );
   XmlNode root =
doc.DocumentElement;
   foreach( XmlNode personElement in
root.ChildNodes )
                //吧节点加入数组
    NodeValues.Add(personElement.FirstChild.Value);
           
//在ListBox中显示
   XMLNodeListBox.DataSource = NodeValues;
   XMLNodeListBox.DataBind();
二:
//读取XML到DataSet
DataSet ds = new DataSet();
ds.ReadXml(Server.MapPath(".\\db\\dbGuest.xml"));
GridView1.Dat


相关文档:

对于带有表空间xmlns的xml文件的解析

对于带有表空间xmlns的xml文件的解析,用正常解析文件的方法总是失效,不起作用,无法获得元素。
下面给出两种方法解析此类文件:
1.按正常解析xml文件的方法,需要注意几点:
获取元素Element,不可使用函数:document.selectNodes("//region");
只可以先取到根元素,一级一级往下取,eg:
Element root = document.g ......

FusionCharts的XML标签属性

FusionCharts 的 XML标签属性有一下四种数据类型
* Boolean - 布尔类型,只能为1或者0。例如:<graph showNames=’1′ >
* Number - 数字类型,只能为数字。例如:<graph yAxisMaxValue=’200′ >
* String - 字符串类型,只能为字符串。例如: <graph caption=’My Chart&r ......

一个用Dom4j解析xml的例子

一、测试用的em.xml
<?xml version="1.0" encoding="GB2312"?>
 <EW cmd="login" mod="Login" version="6.0">
   <Source uns="" type="user"/>
   <Username>zhangzhiyun@hp</Username>
   <Password>111111</Password> ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号