简体   繁体   English

将从SQL Server返回的XML保存在xml文件中

[英]Save the XML returned from the SQL server in xml file

I am using (For XML Auto retrieve all the Table data from sql server. XSLT to style the XML from the server. I want to save the xml returned from the sql server to xml file inside folder ( folder created problematically as well as the xml file) 我正在使用(对于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;


}

} }

Thanks you so much for your help 非常感谢您的帮助

I don't see any save method being called, your creating the xml alright but not writing to a file ie: 我看不到任何保存方法被调用,您创建的xml不错,但是没有写入文件,即:

xd.Save("myxml.xml") xd.Save(“ myxml.xml”)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM