突然在xml中出错 [英] suddenly get errors in xml

查看:91
本文介绍了突然在xml中出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一个按钮,点击后会保存输入的所有信息。它工作了很好,直到突然它没有,我不知道为什么。我收到错误



system.xml.dll中发生未处理的System.Xml.XmlException类型异常

其他信息:系统错误。


我发现当有一些无法识别的

字符时,有时会发生这种情况,所以我甚至开始使用新的xml文件,但它仍然无法工作。

当我试图说出XmlNode Catalog = xml.DocumentElement时,它会对我大吼大叫。为什么会突然停止工作的任何

想法?

谢谢,

Mel


这里'是一些代码:

string cat = @" C:\Catalog4.xml" ;;

XmlDocument xml = new XmlDocument();

xml.Load(cat);


XmlNode Catalog = xml.DocumentElement; (此处为绿色错误箭头)


XmlElement file = xml.CreateElement(" File");

file.InnerText = number.ToString();

Catalog.AppendChild(file);


XmlElement eCust = xml.CreateElement(" Cust");

eCust.InnerText = cust;

file.AppendChild(eCust);

xml.Save(cat);

Hi,
I have a button that, when clicked, saves all the info entered. It worked
fine until suddenly it didn''t, and I have no idea why. I get the error
An unhandled exception of type ''System.Xml.XmlException'' occurred in
system.xml.dll
Additional information: System error.

I found that this sometimes happens when there''s some unrecognized
character, so I even started with a new xml file, but it still won''t work.
It yells at me when I try to say XmlNode Catalog = xml.DocumentElement. Any
ideas on why this would suddenly stop working?
Thanks,
Mel

Here''s some code:
string cat = @"C:\Catalog4.xml";
XmlDocument xml = new XmlDocument();
xml.Load(cat);

XmlNode Catalog = xml.DocumentElement; (green error arrow here)

XmlElement file = xml.CreateElement("File");
file.InnerText = number.ToString();
Catalog.AppendChild(file);

XmlElement eCust = xml.CreateElement("Cust");
eCust.InnerText = cust;
file.AppendChild(eCust);
xml.Save(cat);

推荐答案




melanieab写道:



melanieab wrote:

我收到错误
未处理的异常类型''System.Xml.XmlException''发生在
system.xml.dll中
附加信息:系统错误。


string cat = @" C:\Catalog4.xml" ;;
XmlDocument xml = new XmlDocument();
xml.Load(cat);
I get the error
An unhandled exception of type ''System.Xml.XmlException'' occurred in
system.xml.dll
Additional information: System error.
string cat = @"C:\Catalog4.xml";
XmlDocument xml = new XmlDocument();
xml.Load(cat);




如果标记为

格式不正确,则Load方法会解析XML并抛出异常:

< http://msdn.microsoft.com/library/default.asp? url = / library / en-us / cpref / html / frlrfSystemXmlXmlDocumentClassLoadTopic2.asp>

所以赶上异常,例如

试试{

xml.Load(cat);

}

catch(XmlException e){

//现在检查e.Message,e.LineNumber,e.LinePosition这里

//找出XML解析器无法解析你的标记的原因,例如

}

-

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/


Hi Melanieab,

可以包含Catalog4.xml文件中的内容副本,即

可能有助于更准确地解释你的问题。


Mark R Dawson


" melanieab"写道:
Hi Melanieab,
can you include a copy of what is inside your Catalog4.xml file, that
might help explain more precisely what your problem is.

Mark R Dawson

"melanieab" wrote:

我有一个按钮,点击后,保存输入的所有信息。它工作得很好,直到突然它没有,我不知道为什么。我收到错误

system.xml.dll中发生了'System.Xml.XmlException'类型的未处理异常
附加信息:系统错误。
我发现当有一些无法识别的角色时有时会发生这种情况,所以我甚至开始使用新的xml文件,但它仍然无法正常工作。
当我尝试时它会对我大喊大叫说XmlNode Catalog = xml.DocumentElement。关于为什么会突然停止工作的任何想法?
谢谢,
Mel

这里有一些代码:
string cat = @" C:\Catalog4.xml" ;;
XmlDocument xml = new XmlDocument();
xml.Load(cat);

XmlNode Catalog = xml.DocumentElement; (此处为绿色错误箭头)

XmlElement file = xml.CreateElement(" File");
file.InnerText = number.ToString();
Catalog.AppendChild(file );

XmlElement eCust = xml.CreateElement(" Cust");
eCust.InnerText = cust;
file.AppendChild(eCust);
xml。保存(猫);
Hi,
I have a button that, when clicked, saves all the info entered. It worked
fine until suddenly it didn''t, and I have no idea why. I get the error
An unhandled exception of type ''System.Xml.XmlException'' occurred in
system.xml.dll
Additional information: System error.

I found that this sometimes happens when there''s some unrecognized
character, so I even started with a new xml file, but it still won''t work.
It yells at me when I try to say XmlNode Catalog = xml.DocumentElement. Any
ideas on why this would suddenly stop working?
Thanks,
Mel

Here''s some code:
string cat = @"C:\Catalog4.xml";
XmlDocument xml = new XmlDocument();
xml.Load(cat);

XmlNode Catalog = xml.DocumentElement; (green error arrow here)

XmlElement file = xml.CreateElement("File");
file.InnerText = number.ToString();
Catalog.AppendChild(file);

XmlElement eCust = xml.CreateElement("Cust");
eCust.InnerText = cust;
file.AppendChild(eCust);
xml.Save(cat);



实际上现在,在玩了代码的其他部分后,似乎

我可以'完全不再使用xml了。一开始,我宣布一个私有的

DataTable tCat,然后当我想将信息加载到数据网格中时,我

说tCat = new DataTable(工作正常之前),但现在我得到相同的

错误信息,如下所示。我不知道发生了什么。


" Martin Honnen"写道:
Actually now, after playing around with other sections of the code, it seems
I can''t use xml at all anymore. At the beginning, I declare a private
DataTable tCat, then later when I want to load the info into a datagrid, I
say tCat = new DataTable (which worked fine before), but now I get the same
error message as below. I have no idea what''s going on.

"Martin Honnen" wrote:


melanieab写道:



melanieab wrote:

我收到错误

system.xml.dll中发生未处理的System.Xml.XmlException类型异常
附加信息:系统错误。
I get the error
An unhandled exception of type ''System.Xml.XmlException'' occurred in
system.xml.dll
Additional information: System error.





string cat = @" C:\Catalog4.xml" ;;
XmlDocument xml = new XmlDocument();
xml.Load(cat);
string cat = @"C:\Catalog4.xml";
XmlDocument xml = new XmlDocument();
xml.Load(cat);



如果标记格式不正确,Load方法会解析XML并抛出异常:
< http://msdn.microsoft.com/library/default.asp?url = /library/en-us/cpref/html/frlrfSystemXmlXmlDocumentClassLoadTopic2.asp>
所以抓住异常例如
试试{
xml.Load(cat);
}
catch(XmlException e){
//现在检查e.Message,e.LineNumber,e.LinePosition这里
//找出XML解析器无法解析你的标记的原因,例如
}

-

Martin Honnen --- MVP XML
http: //JavaScript.FAQTs.com/



这篇关于突然在xml中出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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