【问题标题】:Root namespace missing in DataSet.WriteToXmlDataSet.WriteToXml 中缺少根命名空间
【发布时间】:2009-01-22 14:30:22
【问题描述】:

1) 我做了一个 Dataset.WriteToXml(内存流对象) 2) 然后我创建一个 XMLDocument 对象 3)我然后XMLDocument.Load(内存流对象)

我收到“未找到 XML 根命名空间”异常。

Dataset XML 是否不包含所需的命名空间?

谢谢。

【问题讨论】:

    标签: xml dataset namespaces


    【解决方案1】:

    您是否在尝试将内存流加载到 XmlDocument 之前重新定位它?

    DataSet ds = new DataSet();
    using (SqlConnection connection = new SqlConnection("some connection string"))
    using (SqlCommand command = new SqlCommand("select * from mytable", connection))
    using (SqlDataAdapter adapter = new SqlDataAdapter(command))
    {
        adapter.Fill(ds);
    }
    
    XmlDocument xml = new XmlDocument();
    using (Stream stream = new MemoryStream())
    {
        ds.WriteXml(stream);
        // We must reposition the memory stream before loading the xml
        stream.Position = 0;
        xml.Load(stream);
    }
    

    【讨论】:

      猜你喜欢
      • 2018-02-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-22
      相关资源
      最近更新 更多