的XDocument:是否有可能迫使畸形XML文件的加载? [英] XDocument : is it possible to force the load of a malformed XML file?

查看:397
本文介绍了的XDocument:是否有可能迫使畸形XML文件的加载?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个畸形的XML文件。根标签没有被标记关闭。最终的标签丢失。

I have a malformed XML file. The root tag is not closed by a tag. The final tag is missing.

当我尝试加载我的畸形XML文件在C#

When I try to load my malformed XML file in C#

StreamReader sr = new StreamReader(path);
batchFile = XDocument.Load(sr); // Exception



我得到一个异常的出现意外的文件结尾。以下元素未封闭:54号线批次,位置1

是否有可能忽略结束标记或强制加载。?我注意到,我所有的XML工具((如XML记事本))全自动修复或忽略的问题。我不能修复XML文件。从第三方软件这一块copme,有时该文件是正确的。

Is it possible to ignore the close tag or to force the loading? I noticed that all my XML tools ((like XML notepad) ) automaticly fix or ignore the problem. I can not fix the XML file. This one copme from a third party software and sometimes the file is correct.

推荐答案

您不能用的XDocument 因为这个类加载在内存中的所有文件,并完全地解析它。结果
,而它可以处理与的XmlReader 这将让你阅读和处理完整的文档,并在年底你会得到缺少的标签exeption。

You cant do it with XDocument because this class loads all document in memory and parse it completly.
But its possible to process document with XmlReader it would get you to read and process complete document and at the end youll get missing tag exeption.

这篇关于的XDocument:是否有可能迫使畸形XML文件的加载?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆