
Signature
Anthony Jones - MVP ASP/ASP.NET
The files are over 150MBs.
I am trying to build something that will be generic, something that I
can use for any xml file. I want to write the data as rows to a
database table with columns; col1, col2, col3 etc. I do not think
that OPENXML will work for me.
<Nam>ABC</Nam>
<envText>P</envText>
<rptC>XY123</rptCd>
<rptNam>Detail</rptNam>
<membNam>MY COMPANY</membNam>
<rptPrntEDat>2008-01-31</rptPrntEDat>
<rptPrntRDat>2008-01-31</rptPrntRDat>
</rptHdr>
- <cb999Grp>
- <cb999KeyGrp>
<membClgIdCod>MISC</membClgIdCod>
</cb999KeyGrp>
- <cb999Grp1>
- <cb999KeyGrp1>
<membxIdCod>PPLO</membxIdCod>
</cb999KeyGrp1>
- <cb999Grp2>
- <cb999KeyGrp2>
<currTypCod>EUR</currTypCod>
</cb999KeyGrp2>
- <cb999Grp3>
- <cb999KeyGrp3>
<acctTypGrp>A1</acctTypGrp>
</cb999KeyGrp3>
- <cb999Grp4>
- <cb999KeyGrp4>
<prodTypId>FDOO</prodTypId>
<prodId>GBHH</prodId>
</cb999KeyGrp4>
<fSiz>0.01</fSiz>
<fVal>10.0000</fVal>
- <cb999Grp5>
- <cb999KeyGrp5>
- <cntrDtlClassGrp>
<cntrClasCod>C</cntrClasCod>
- <cntrDtlGrp>
<cntrpoMthDat>3</cntrpoMthDat>
<cntrpoYrDat>2008</cntrpoYrDat>
....and it keeps going. For this file, the depth is 15 levels.
Any help would be appreciated.
Anthony Jones - 14 Feb 2008 09:26 GMT
> The files are over 150MBs.
>
[quoted text clipped - 43 lines]
>
> ....and it keeps going. For this file, the depth is 15 levels.
Use a SqlCommand that uses OPENXML to parse and insert the data for a single
record.
Use System.Xml.XmlTextReader will allow you parse throught this Xml file as
stream. move passed the root node(s) until you are at the first node that
represents a record. Use ReadOuterXml to retrieve an XML string for just
one record and execute your command.
In this approach you never need to load the whole thing in memory.

Signature
Anthony Jones - MVP ASP/ASP.NET