ASP.NET页面输出XML(C#)

  private void Page_Load(object sender, System.EventArgs e)
  {
   // 在此处放置用户代码以初始化页面
   XmlDocument ObjXML = new XmlDocument();//创建XMLDOCUMENT对象
   XmlElement root = ObjXML.CreateElement("root");//创建根节点对象
   ObjXML.AppendChild(root);//插入根节点
   XmlElement user = ObjXML.CreateElement("user");//创建子节点对象
   root.AppendChild(user);//插入子节点
   user.SetAttribute("name",null,"liyan");//设置节点属性
   user.SetAttribute("passwd",null,"123");//设置节点属性
 
   XmlDeclaration xmldecl;
   xmldecl = ObjXML.CreateXmlDeclaration("1.0",null,null);
   xmldecl.Encoding="UTF-8";
   ObjXML.InsertBefore(xmldecl,root);
   string myxml = ObjXML.InnerXml.ToString();//插入XML类型头
   Response.Write(myxml);//在页面输出XML文本
  }
Advertisements

One response to this post.

  1. Posted by 张留明 on 九月 6, 2009 at 3:05 上午

    老大,我这怎么在页面没有数据显示?

    回复

发表评论

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 更改 )

Twitter picture

You are commenting using your Twitter account. Log Out / 更改 )

Facebook photo

You are commenting using your Facebook account. Log Out / 更改 )

Google+ photo

You are commenting using your Google+ account. Log Out / 更改 )

Connecting to %s

%d 博主赞过: