如何反序列化不是XML文件的文本文件. [英] How to deserialize a text file which is not an XML file.

查看:79
本文介绍了如何反序列化不是XML文件的文本文件.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

要序列化XML文件,我使用了Serializier.Deserialze(reader).从XML文件中获取数据非常好.问题是我必须反序列化非XML格式的文件.我想到了两种方法:
1.创建一个适配器将文本文件转换为XML数据,然后使用我的程序反序列化XML文件.
2.如果可以,请直接对文本文件进行反序列化

如果选择第一种方法,该如何转换为XML数据?我是否必须手动逐行读取文本文件?这似乎太乏味了.你有什么建议吗?或者,也许您有更好的解决方案-可能会稍微更改文件格式?请告知.


MyFile.data
[Input1]
数据字符串1
[Input2]
数据字符串2
[DataSet]
[1]
最小
2
美元

[2]
最大
3
美元

[3]
一些描述
111
SomeUnits

...

To serialize an XML file, I used Serializier.Deserialze(reader). This is terrific to get data out of an XML file. The problem is that I'll have to Deserialize a file that is not in XML format. I thought of 2 approaches:
1. Create an adapter to convert the text file to XML data, then use my program to deserialize the XML file.
2. Deserialze the text file directly, if there's a way

If I select the first approach, how do I convert to XML data? Do I have to manually read line-by-line in the text file? It seems to be too tedious. Do you have any suggestion? Or maybe you've got a better solution - probably change the file format a little bit? Please advise.


MyFile.data
[Input1]
               Data string 1
[Input2]
               Data string 2
[DataSet]
  [1]
Minimum
2
dollars

  [2]
Maximum
3
Dollars             

   [3]
Some description
111
SomeUnits

...

推荐答案



在System.Runtime.Serialization.Formatters.Binary中使用BinaryFormatter

http://msdn.microsoft.com/en-us/library/c5sbs8z9 .aspx

看看上面的示例.这非常符合您的要求.

希望这会有所帮助.

,谢谢,
贾加迪什·克里希南(Jagadish Krishnan)
Hi,

Use BinaryFormatter in System.Runtime.Serialization.Formatters.Binary

http://msdn.microsoft.com/en-us/library/c5sbs8z9.aspx

Have a look at the example above. This is very near to your requirement.

Hope this helps a bit.

Thanks,
Jagadish Krishnan


这篇关于如何反序列化不是XML文件的文本文件.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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