Click here to Skip to main content
15,936,709 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi guys,
I am hoping somebody can help me with this.
I am trying to parse a very large XML file. I am first reading the file line by line and then using XML reader to parse each line.

The line looks like this (The file has about 20000 lines like this):

<fieldinfo><fieldno>ABCDE</fieldno><desc><![CDATA[bubbles</desc><indicative><comcd>FCH</comcd><prodcls>6Q</prodcls><actyind>M</actyind><mi>003</mi><assmind>0</assmind><attind>0</attind><noncurrdt>0401</noncurrdt><frtrdind>0</frtrdind><fldcarrind>0</fldcarrind><hazmattind>0</hazmattind><pkgqtyind>0</pkgqtyind><pkgqty>1</pkgqty><weight><net>0.51</net><gross>0.51</gross></weight><dimension><len>4.5</len><ht>1.7</ht><wdt>4.0</wdt></dimension><rplmts><ind>0</ind><type>0</type></rplmts></indicative><pricing><nmp>NO</nmp><dlrcd>AB31</dlrcd><mkttyp>PRODUCT</mkttyp><aggtyp>TEPSF</aggtyp><mo>NACD</mo><sa>NACD  </sa><ccy>USD</ccy><effdt>20110701</effdt><net><prdprc>32.31</prdprc><crdep>1.0</crdep><dmgcrrfnd>0.0</dmgcrrfnd><totprcwdmgcr>0.0</totprcwdmgcr></net><lst><prdprc>46.0</prdprc><crdep>0.0</crdep><dmgcrrfnd>0.0</dmgcrrfnd><totprcwdmgcr>0.0</totprcwdmgcr></lst><fon><prdprc>41.4</prdprc><crdep>0.0</crdep><dmgcrrfnd>0.0</dmgcrrfnd><totprcwdmgcr>0.0</totprcwdmgcr></fon><otr><prdprc>33.96</prdprc><crdep>0.0</crdep><dmgcrrfnd>0.0</dmgcrrfnd><totprcwdmgcr>0.0</totprcwdmgcr></otr><stk><prdprc>0.0</prdprc><crdep>0.0</crdep><dmgcrrfnd>0.0</dmgcrrfnd><totprcwdmgcr>0.0</totprcwdmgcr></stk></pricing></fieldinfo>

I am trying to parse various element values from the file lines and then reading another line.
Fields I need to parse are:
<lst><prdprc> value and so on

I am currently using an example from microsoft website using a case statement to read the name of the element and then using ReadToFollowing to go to fields like prdPrc. For some reason some values are not being returned and others are. Please help!!!

Thanks in advance
Updated 18-Nov-11 17:30pm

Well, don't read file. Use one of .NET XML parsers. Here is short overview of them:

  1. Use System.Xml.XmlDocument class. It implements DOM interface; this way is the easiest and good enough if the size if the document is not too big.
  2. Use the class System.Xml.XmlTextReader; this is the fastest way of reading, especially is you need to skip some data.
  3. Use the class System.Xml.Linq.XDocument; this is the most adequate way similar to that of XmlDocument, supporting LINQ to XML Programming.

As your file is big, System.Xml.XmlTextReader might be the best. However, it also depends on what do you want to do with the results of parsing.

Share this answer
You Parse your xml using following C# code,u will get each element name and text
containg that.

add namespace - using System.Xml;
on button click write code as-
XmlTextReader reader = new XmlTextReader("C:\\Users\\Dell\\Desktop\\New folder\\XMLFile1.xml"); //this will location and name of xml

while (reader.Read())
switch (reader.NodeType)
case XmlNodeType.Element: // The node is an element.
MessageBox.Show("<" + reader.Name);
case XmlNodeType.Text: //Display the text in each element.
case XmlNodeType.EndElement: //Display the end of the element.
//Console.Write("</" + reader.Name);

By this sample u can read any type of xml and retrive any node,innernode or any text of xml.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900