生成XML文档时出错 [英] There was an error generating the XML document
问题描述
您好
我看到"生成XML文档时出错"当我运行我的程序而我无法理解为什么?我是C#的新手
I see "There was an error generating the XML document" when I run my program and I cant understand why?I am new in C#
请告知
public
class
SerializableData
{
public
void
save( string
filename) 字符串
tmpFileName;
public void save(string filename) String tmpFileName;
{
{
tmpFileName =
filename + " .tmp" ;
FileInfo
tmpFileInfo = new
FileInfo (tmpFileName);
if
(tmpFileInfo.Exists) FileStream
stream = new
FileStream (tmpFileName,
< span style ="font-family:Consolas; color:#2b91af; font-size:x-small"> FileMode .Create);
true );
tmpFileName = filename +".tmp"; FileInfo tmpFileInfo = new FileInfo(tmpFileName); if (tmpFileInfo.Exists) FileStream stream = new FileStream(tmpFileName, FileMode.Create); true);
  ;
tmpFileInfo.Delete();
tmpFileInfo.Delete();
save(stream);
save(stream);
stream.Close();
stream.Close();
tmpFileInfo.CopyTo(filename,
tmpFileInfo.CopyTo(filename,
tmpFileInfo .Delete();
tmpFileInfo.Delete();
}
公开
void
保存( Stream
stream)
public void save(Stream stream)
{
XmlSerializer
serializer = new
XmlSerializer ( typeof ( SerializableData ));
XmlSerializer serializer = new XmlSerializer(typeof(SerializableData));
serializer.Serialize(stream,
serializer.Serialize(stream,
}
}
谢谢
推荐答案
你可以把一个try catch块放到抛出并粘贴exception.ToString()的代码里面。上面的代码也是不完整的。你能复制粘贴代码吗?再次?我尝试了下面的代码,它序列化了SerializableData类。
You can put a try catch block arond the code which throws and paste exception.ToString() here. Also the code above is incomplete. Can you please copy paste the code again? I tried following code and it serialized the class SerializableData.
public class SerializableData
{
public int MyData { get; set; }
public static void Save()
{
XmlSerializer ser = new XmlSerializer(typeof(SerializableData));
ser.Serialize(Console.Out, new SerializableData() { MyData = 12 });
}
}
谢谢,
Neha Garg
Neha Garg
这篇关于生成XML文档时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!