aspx输入xml

来源:互联网 发布:linux exec fork 编辑:程序博客网 时间:2024/05/17 18:04
 

 // 在此处放置用户代码以初始化页面 

            XmlDocument ObjXML = new XmlDocument();//创建XMLDOCUMENT对象 

            XmlElement root = ObjXML.CreateElement("root");//创建根节点对象           

            XmlElement user = ObjXML.CreateElement("user");//创建子节点对象 

           

            user.SetAttribute("name", null, "liyan");//设置节点属性 

            user.SetAttribute("passwd", null, "123");//设置节点属性 

            root.AppendChild(user);//插入子节点 

            ObjXML.AppendChild(root);//插入根节点 

            XmlDeclaration xmldecl;

            xmldecl = ObjXML.CreateXmlDeclaration("1.0","gb2312",null);

            xmldecl.Encoding = "UTF-8";

            ObjXML.InsertBefore(xmldecl, root);

            string myxml = ObjXML.InnerXml.ToString();//插入XML类型头 

 

            Response.Write(myxml);//在页面输出XML文本 

原创粉丝点击