XML 序列化程序跳过行

发布于 2024-11-05 18:53:39 字数 745 浏览 0 评论 0原文

我有一个从数据库读取记录并将其导出到 xml 文件的应用程序。有一个 xsd 可以绘制 xml 文件的架构。我使用 xsd 代理类将数据序列化为 xml 文件。

这就是我将数据序列化为 xml 的方式:

XmlSerializer serializer = new XmlSerializer(_report.GetType());
StringBuilder xmlString = new StringBuilder();
StringWriter writer = new StringWriter(xmlString);
serializer.Serialize(writer, _report);
XmlDocument doc = new XmlDocument();
doc.LoadXml(xmlString.ToString());
doc.Save(_outputFile.FullName);

我遇到的问题是输出文件中缺少行。我进行了调试,发现数据被添加到数据库中的代理对象集合中,并通过“_report”对象传递到序列化器。

因此,为了隔离数据或应用程序的问题,我将一些丢失的记录手动编码到 csv 文件中,并将数据导入到我的应用程序中。这些记录现在出现在 xml 文件中。所以,现在我知道这是一个数据问题。该应用程序使用 informix 数据库作为后端。

我不明白的是,为什么 informix 数据库中同一个表中的某些行存在而其他行不存在?我花了将近2-3天的时间在互联网上查找,但没有成功。所以,我认为是时候把它提高一个档次了。

I have an application that reads records from the database and exports it out to an xml file. There is a xsd in place that draws out the schema of the xml file. I am using the xsd proxy classes to then serialize the data to xml file.

This is how I am serializing the data to xml:

XmlSerializer serializer = new XmlSerializer(_report.GetType());
StringBuilder xmlString = new StringBuilder();
StringWriter writer = new StringWriter(xmlString);
serializer.Serialize(writer, _report);
XmlDocument doc = new XmlDocument();
doc.LoadXml(xmlString.ToString());
doc.Save(_outputFile.FullName);

The problem I am having is that in the output file there are missing rows. I went through the debug and found out that the data is being added to the collection of the proxy objects from the database and getting passed to the serializer via the '_report' object.

So to isolated the issue of data or app, I hand coded a few of the missing records into a csv file and imported the data into my app. Those records were now appearing in the xml file. So, now I know that this is a data issue. The app is using informix database as the backend.

What I don't understand is that why some of the rows from the same table in the informix database be present and other not? I have spent almost 2-3 days on this looking around on the INTERNET without any success. So, I figured its time to turn it up a notch.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

绝不服输 2024-11-12 18:53:39

2天前我也遇到了类似的问题。

尝试

 writer.Flush();

在致电之前

 xmlString.ToString());

添加这是解决我的问题。

I had a similar problem 2 day ago.

try adding

 writer.Flush();

before you call

 xmlString.ToString());

That was the solution that solved my problem.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文