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
相关文档:
前段时间用jQuery做了个小练习,获取本地的xml数据,在firefox下面测试没问题,但是在IE下面总是获取数据失败,上网找了很久也没找到是怎么回事。郁闷了很长一段时间,今天有空又把这个问题拿出来研究了下,最后终于找到原因了,把页面放到服务器去浏览就OK了。难道是权限问题?不知道怎么火狐在本地目录可以获取数据成功。 ......
一、测试用的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> ......
Retrieving an XML document using Ajax
http://www.javascriptkit.com/dhtmltutors/ajaxgetpost3.shtml
When making a server request in Ajax, the data returned can be in either
plain text/html, or an XML document instead. The later is technically
just a text file as well, but with s ......