转载:http://www.cnblogs.com/xiaofengfeng/archive/2010/08/31/1813181.html
ASP.NET页面输出XML(C#)
private
void
Page_Load(
object
sender, System.EventArgs e)
{
XmlDocument ObjXML =
new
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();
Response.Write(myxml);
}