Vb.net代码读取大型xml文件 [英] Vb.net code to read large xml file

查看:74
本文介绍了Vb.net代码读取大型xml文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是.net的新手,需要你的帮助。



请提供vb.net代码来读取大型xml文件然后它应该删除从代码中的十六进制,然后我们应该在数据集中加载xml文件。从数据集我们可以使用数据表在日志文件中显示它。



我尝试过:



我试过以下。



1.'TS = FSO.OpenTextFile(sFTPLogXml,IWshRuntimeLibrary.IOMode.ForReading)'-sFTPLog = >原始日志文件

'最终= TS.ReadAll

'TS.Close()



2.' Final = File.ReadAllText(sFTPLogXml)'TAS-在这里因内存不足而失败,试图读取整个文件。输入文件变得很大

I'm new to .net and need your help .

Please provide me the vb.net code to read the large xml file then it should remove the hexadecimal from code then we should load the xml file in dataset. from dataset we can display that in log files by using datatables.

What I have tried:

I have tried with following.

1. 'TS = FSO.OpenTextFile(sFTPLogXml, IWshRuntimeLibrary.IOMode.ForReading) '-sFTPLog => Original Log file
'Final = TS.ReadAll
'TS.Close()

2.'Final = File.ReadAllText(sFTPLogXml) 'TAS-fails here with out of memory error, trying to read the entire file. The input file gets pretty big

推荐答案

你做错了。您需要在阅读时解析XML,而无需在中间文本文件中读取它。您是否希望在内存中使用双重数据集,从文件中解析原始XML和XML?这是荒谬的,特别是当你担心内存限制时。



解析.NET FCL提供的XML的最经济,最快捷的方法是 System.Xml.XmlReader ,它应直接在磁盘或流上的文件上运行,而不使用任何中间文本:

XmlReader类(System.Xml) [ ^ ]。



现在,最终文件的大小可能会超出可用系统RAM的限制。 x86进程特别容易受到4G地址空间的限制,真正可用的内存将会少得多。在64位系统中使用WOW64的情况是x86(32位)进程可能会相当好(你不需要整个操作系统驻留在这个内存的一部分),但原理限制仍然是相同的。



因此,通过这种方法,您可以开发解析文件部分的技术,跳过不再需要的节点。 System.Xml.XmlReader 的一个好处是,您只能浏览XML树,但实际上只能在内存中读取并存储您想要的内容。



这个想法的替代实现可以通过另一种XML解析方法实现。您可以使用类 System.Xml.Linq.XDocument ;这是类似于 XmlDocument 的最合适的方式,支持 LINQ to XML 编程。请参阅:

http://msdn.microsoft.com /en-us/library/system.xml.xmldocument.aspx http:// msdn .microsoft.com / zh-CN / library / bb387063.aspx

LINQ to XML Overview [ ^ ],

LINQ to XML [ ^ ]。



-SA
You did it wrong. You need to parse XML as you read, without reading it in intermediate text file. Do you want to have double set of data in your memory, raw XML and XML parsed from a file? This is absurd, especially when your concern is the memory limitation.

Most economic and fast way of parsing XML offered by .NET FCL is the class System.Xml.XmlReader, which should operate directly on a file on disk or a stream, without using any intermediate text:
XmlReader Class (System.Xml)[^].

Now, eventually the size of a file can grow beyond the limit of available system RAM. It's especially easy with x86 processes which are limited by 4G of address space, and really available memory will be considerably less. With WOW64 in a 64-bit system the situation is with a x86 (32-bit) process can be considerably better (you don't need the whole OS to reside in part of this memory), but principle limitation is still the same.

So, with this approach, you can develop the technique of parsing just the part of file, skipping nodes which are no longer needed. One benefit of System.Xml.XmlReader is that you only navigate through XML tree, but actually read and store in memory only what you want.

The alternative implementation of this idea can be achieved with another XML parsing approach. You can use the class System.Xml.Linq.XDocument; this is the most adequate way similar to that of XmlDocument, supporting LINQ to XML programming. Please see:
http://msdn.microsoft.com/en-us/library/system.xml.xmldocument.aspx, http://msdn.microsoft.com/en-us/library/bb387063.aspx,
LINQ to XML Overview[^],
LINQ to XML[^].

—SA


这篇关于Vb.net代码读取大型xml文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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