473,395 Members | 2,253 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Parse large xml file into excel using vba

Hello,

I have a code with which I can parse a file of around 1MB. However I am looking to parse an xml file of about 128MB.

Below is my code

Expand|Select|Wrap|Line Numbers
  1. Dim xml_doc As New DOMDocument
  2. Dim brtn As Boolean
  3.  
  4. Dim xnode As IXMLDOMElement
  5. Dim snode As IXMLDOMElement
  6.  
  7. Dim intr As Long
  8. Dim tmp As Long
  9.  
  10.  
  11.  
  12. Sheet1.Cells.Clear
  13.  
  14. '
  15. file = Application.GetOpenFilename("Choose xml File (*.xml*),*.*", , "Openxml File")
  16. brtn = xml_doc.Load(file)
  17.  
  18. intr = 2
  19. tmp = 2
  20.  
  21. Sheet1.Cells.ClearFormats
  22.  
  23. If brtn Then
  24.  
  25.     With Sheets("Sheet1")
  26.     .Cells(1, 1) = "Node"
  27.     .Cells(1, 2) = "Version"
  28.     .Cells(1, 3) = "distName"
  29.     .Cells(1, 4) = "ID"
  30.     .Cells(1, 5) = "Managed Object"
  31.     .Cells(1, 6) = "Value"
  32.  
  33.  
  34.  
  35.     Range("A1", "F1").Font.Bold = True
  36.     Sheet1.Range("A1", "F1").HorizontalAlignment = xlCenter
  37.  
  38.  
  39.  
  40.  
  41.           For Each snode In xml_doc.SelectNodes("//managedObject")
  42.  
  43.             For Each xnode In snode.ChildNodes
  44.  
  45.  
  46.  
  47.  
  48.                   .Cells(intr, 1) = snode.getAttribute("class")
  49.                   .Cells(intr, 2) = snode.getAttribute("version")
  50.                   .Cells(intr, 3) = snode.getAttribute("distName")
  51.                   .Cells(intr, 4) = snode.getAttribute("id")
  52.                   .Cells(intr, 5) = xnode.getAttribute("name")
  53.                   .Cells(intr, 6) = xnode.Text
  54.  
  55.  
  56.                   intr = intr + 1
  57.  
  58.             Next
  59.  
  60.           Next
  61.  
  62.  
  63.  
  64.  
  65.  
  66.       End With
  67. Else
  68. MsgBox "Unable to open xml file...."
  69.  
  70. End If
  71. EndParse:
  72. End Sub
Please let me know if there is any possible way to load around 250000 elements.

I read in some other article that DOM loads the whole file before parsing. The file size is more than 128 MB so my PC gets hang before showing result in the excel file.

It also read SAX is the efficient method. So I am not sure which one to use SAX or an array or stream all elements one by one?

Thank you

Chins
Jun 15 '10 #1
0 2947

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: liming | last post by:
Hi all, I have to parse two text files on a weekly basis. Each range from 300kb to 1mb in total. Each text file has 5 columns (name,id, dollar, startdate,enddate), everytime, a) I need to...
5
AdrianH
by: AdrianH | last post by:
Assumptions I am assuming that you know or are capable of looking up the functions I am to describe here and have some remedial understanding of C++ programming. FYI Although I have called...
1
AdrianH
by: AdrianH | last post by:
Assumptions I am assuming that you know or are capable of looking up the functions I am to describe here and have some remedial understanding of C programming. FYI Although I have called this...
0
by: bebek_tetangga | last post by:
Hello, I'm trying to open a .txt file in Excel using C#. Here is my code: clsWorkbook = clsExcel.Workbooks.Open(dailyPath + "\\070701N.txt", 2, false, 5, "", "", true,...
1
by: CoolFactor | last post by:
MY CODE IS NEAR THE BOTTOM I want to export this Access query into Excel using a command button on an Access form in the following way I describe below. Below you will find the simple query I am...
0
by: wankhusairi | last post by:
hallo sir .. i am still new on using vb and i have tried to load an excel using a visual basic interface.. but if i wanted to plot my excel data what should i do.. must i cahnge my program on loading...
1
by: =?Utf-8?B?YXNob2tuYW5kaA==?= | last post by:
Hi, I am using a native asp.net file upload technic which currently supports small files. But i need to upload the file of size more than 200 mb to 300 mb. I have used many 3rd party...
0
by: dodoG | last post by:
Hello, How to parse html file tags <h1>-<h4> to excel file with c#. 1. How i create excel 2007 object . 2. What should i do in visual studio 2005 (which references in com object). 3. How i...
1
by: zcabeli | last post by:
hello, i've got XML file which contain the following records as shown in example below. <group name="ddd" > <param name="abc" def="0xc" tag="1" encapsulated="1" PATH...
6
by: =?Utf-8?B?RGF2aWRN?= | last post by:
Hello, I have an XML file generated from a third party application that I would like to parse. Ideally, I plan on having a windows service setup to scan various folders for XML files and parse the...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.