我正在使用(对于 XML 自动从 sql server 检索所有表数据。XSLT 来设置来自服务器的 XML 样式。我想将从 sql server 返回的 xml 保存到文件夹内的 xml 文件中(创建有问题的文件夹以及 xml文件)
protected void Page_Load(object sender, EventArgs e)
{
string strConnenction = System.Configuration.ConfigurationManager.
ConnectionStrings["Connectionstring0034"].ConnectionString;
XmlDocument xd = new XmlDocument();
XPathNavigator xpathnav = xd.CreateNavigator();
using (SqlConnection conn = new SqlConnection(strConnenction))
{
conn.Open();
SqlCommand command = new SqlCommand(
"select * from Employees as products for XML AUTO, ELEMENTS", conn);
using (XmlWriter xw = xpathnav.PrependChild())
{
xw.WriteStartElement("products");
using (XmlReader xr = command.ExecuteXmlReader())
{
xw.WriteNode(xr, true);
}
xw.WriteEndElement();
}
}
XmlProducts.XPathNavigator = xpathnav;
}
}
非常感谢你的帮助