【发布时间】:2021-03-24 01:48:52
【问题描述】:
所以我一直在为一个项目编写一段旧代码。 我已经设法针对 64 位使用对其进行了优化。 但是只有1个问题。使用 XmlSerializer.Deserialize 时 它中断是因为输入文本/反序列化数据太大。 (溢出/超过 2gb int 限制)。
我试图找到解决方法,但没有任何帮助。
这是有问题的代码。
if (File.Exists(dir + "/" + fileName))
{
string XmlString = File.ReadAllText(dir + "/" + fileName, Encoding.UTF8);
BXML_LIST deserialized;
using (MemoryStream input = new MemoryStream(Encoding.UTF8.GetBytes(XmlString)))
{
using (XmlTextReader xmlTextReader = new XmlTextReader(input))
{
xmlTextReader.Normalization = false;
XmlSerializer xmlSerializer = new XmlSerializer(typeof(BXML_LIST));
deserialized = (BXML_LIST)xmlSerializer.Deserialize(xmlTextReader);
}
}
xml_list.Add(deserialized);
}
根据这里提出的许多问题,我认为我可以使用一种方法来“拆分”xml 文件(同时保持相同类型的 BXML_LIST) 然后对其进行反序列化并完成:将其组合以匹配其原始内容,以避免在反序列化整个文件时出现溢出错误。
问题是,我不知道如何实现这一点。任何帮助或指导都会很棒!
// 编辑1:
我从另一个站点找到了一段代码,不知道它是否是组合拆分后的xml文件的可靠方法:
var xml1 = XDocument.Load("file1.xml");
var xml2 = XDocument.Load("file2.xml");
//Combine and remove duplicates
var combinedUnique = xml1.Descendants("AllNodes")
.Union(xml2.Descendants("AllNodes"));
//Combine and keep duplicates
var combinedWithDups = xml1.Descendants("AllNodes")
.Concat(xml2.Descendants("AllNodes"));
【问题讨论】:
-
为了帮助您,我们需要了解您的 XML 的结构并查看 BXML_LIST 代码。发布它们。
标签: c# xml xmlserializer xmlstreamreader xdoc