467,077 Members | 1,152 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,077 developers. It's quick & easy.

How to Parse XML File

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 file, then spit out totals.

Since I haven't worked with XML too much in C#, I'm trying to develop a
structured and easy-to-read way to parse the file.

Essentially, I would like to read the file and add the "BatchTktAmountfor
any <Batchelements that may exist. There could be 1 or more...

As a verification, I may also want to add the <BATCH\Itemselements, there
could be 1 or more, and if <Genderis a credit "CR", accumulate totals for
credit items. If <Genderis a debit "DR", acculate totals for debit items.

Total items should equal the total batches.

I guess if I had relatively good XML parsing code, I could figure out how to
read the file in such a way to get the information. The real kicker for me
is the multiple batches and items.

Sample is below.

Any help would be appreciated

<FileExchange>
<Version>
<MajorVer>1</MajorVer>
<MinorVer>0</MinorVer>
</Version>
<Jobs>
<Job>
<StartTime>20080610:171706</StartTime>
<EndTime>20080610:171747</EndTime>
<BusinessDate>20080610</BusinessDate>
<Device>26</Device>
<Site/>
<ProcType>Prime</ProcType>
<WorkTypeNumber>1</WorkTypeNumber>
<ClearingType>OutClearing</ClearingType>
<DebitsFirst>FALSE</DebitsFirst>
<SortFamily>900</SortFamily>
<Imaged>TRUE</Imaged>
<NbrOfBlocksInJob>1</NbrOfBlocksInJob>
<CycleID>A</CycleID>
<Blocks>
<Block>
<BlkNbr>64</BlkNbr>
<BlkStartTime>20080610:171706</BlkStartTime>
<BlkEndTime>20080610:171747</BlkEndTime>
<BlkSeqInJob>1</BlkSeqInJob>
<BlkFrontImgFileName>\\VMSERVER1\MyApp\AllItemsExt ract\G179BC\0064_5.fim</BlkFrontImgFileName>
<BlkRearImgFileName>\\VMSERVER1\MyApp\AllItemsExtr act\G179BC\0064_5.rim</BlkRearImgFileName>
<Batches>
<Batch>
<BatchNbr>1</BatchNbr>
<BranchData>
<BranchID>079010</BranchID>
<BranchDeviceID>79010</BranchDeviceID>
<BranchTill>0</BranchTill>
<BranchBatchNbr>1</BranchBatchNbr>
<BranchBusinessDate>20080610</BranchBusinessDate>
</BranchData>
<BatchTktAmount>617181.39</BatchTktAmount>
<BatchTktTC/>
<BatchTktAN/>
<BatchTktRT>444444442</BatchTktRT>
<BatchTktAux/>
<Items>
<Item>
<ISN>790100003 </ISN>
<ImageDocID>12478</ImageDocID>
<Gender>CR</Gender>
<Amount>17000.00</Amount>
<TC>009</TC>
<AN>0120000153</AN>
<Fld4/>
<RT>5300-1000</RT>
<RIC/>
<Aux/>
<ACHCode>Check21</ACHCode>
<ACHConvertedRT/>
<ACHConvertedAccount/>
<IsElectronic>FALSE</IsElectronic>
<IsOnUs>TRUE</IsOnUs>
<IsDeleted>FALSE</IsDeleted>
<IsInsert>FALSE</IsInsert>
<IsCorrected>FALSE</IsCorrected>
<IsReject>FALSE</IsReject>
<RejectReason>0</RejectReason>
<OutsortReason>0</OutsortReason>
<Availability>0</Availability>
<AppCode>0</AppCode>
<SPSelector>1000</SPSelector>
<Currency>USD</Currency>
<AdjustmentType>0</AdjustmentType>
<AdjustmentReason>0</AdjustmentReason>
<Images>
<Image>
<ImageView>Front</ImageView>
<ImageType>CCITTG4</ImageType>
<ImageOffSet>514</ImageOffSet>
<ImageLength>6298</ImageLength>
</Image>
<Image>
<ImageView>Rear</ImageView>
<ImageType>CCITTG4</ImageType>
<ImageOffSet>514</ImageOffSet>
<ImageLength>5240</ImageLength>
</Image>
</Images>
<CustomerUserInfo>
<Field1>t5300-1000t0120000153o009</Field1>
<Field2>1001</Field2>
<Field3/>
<Field4/>
</CustomerUserInfo>
</Item>
<Item>
<ISN>790100004 </ISN>
<ImageDocID>12479</ImageDocID>
<Gender>DR</Gender>
<Amount>17000.00</Amount>
<TC>1011</TC>
<AN>362343062</AN>
<Fld4/>
<RT>999999999</RT>
<RIC/>
<Aux/>
<ACHCode>Check21</ACHCode>
<ACHConvertedRT/>
<ACHConvertedAccount/>
<IsElectronic>FALSE</IsElectronic>
<IsOnUs>FALSE</IsOnUs>
<IsDeleted>FALSE</IsDeleted>
<IsInsert>FALSE</IsInsert>
<IsCorrected>FALSE</IsCorrected>
<IsReject>FALSE</IsReject>
<RejectReason>0</RejectReason>
<OutsortReason>0</OutsortReason>
<Availability>0</Availability>
<AppCode>0</AppCode>
<SPSelector>8000</SPSelector>
<Currency>USD</Currency>
<AdjustmentType>0</AdjustmentType>
<AdjustmentReason>0</AdjustmentReason>
<Images>
<Image>
<ImageView>Front</ImageView>
<ImageType>CCITTG4</ImageType>
<ImageOffSet>6812</ImageOffSet>
<ImageLength>7624</ImageLength>
</Image>
<Image>
<ImageView>Rear</ImageView>
<ImageType>CCITTG4</ImageType>
<ImageOffSet>5754</ImageOffSet>
<ImageLength>2820</ImageLength>
</Image>
</Images>
<CustomerUserInfo>
<Field1>t031301422t362343062o1011</Field1>
<Field2>8000</Field2>
<Field3/>
<Field4>0011000110000000000000000</Field4>
</CustomerUserInfo>
</Item>
<Item>
<ISN>790100005 </ISN>
<ImageDocID>12480</ImageDocID>
<Gender>CR</Gender>
<Amount>12405.18</Amount>
<TC>109</TC>
<AN>014002437</AN>
<Fld4/>
<RT>5009-1000</RT>
<RIC/>
<Aux/>
<ACHCode>Check21</ACHCode>
<ACHConvertedRT/>
<ACHConvertedAccount/>
<IsElectronic>FALSE</IsElectronic>
<IsOnUs>TRUE</IsOnUs>
<IsDeleted>FALSE</IsDeleted>
<IsInsert>FALSE</IsInsert>
<IsCorrected>FALSE</IsCorrected>
<IsReject>FALSE</IsReject>
<RejectReason>0</RejectReason>
<OutsortReason>0</OutsortReason>
<Availability>0</Availability>
<AppCode>0</AppCode>
<SPSelector>1000</SPSelector>
<Currency>USD</Currency>
<AdjustmentType>0</AdjustmentType>
<AdjustmentReason>0</AdjustmentReason>
<Images>
<Image>
<ImageView>Front</ImageView>
<ImageType>CCITTG4</ImageType>
<ImageOffSet>14436</ImageOffSet>
<ImageLength>4934</ImageLength>
</Image>
<Image>
<ImageView>Rear</ImageView>
<ImageType>CCITTG4</ImageType>
<ImageOffSet>8574</ImageOffSet>
<ImageLength>4145</ImageLength>
</Image>
</Images>
<CustomerUserInfo>
<Field1>t5009-1000t109</Field1>
<Field2>1003</Field2>
<Field3/>
<Field4/>
</CustomerUserInfo>
</Item>
<Item>
<ISN>790100006 </ISN>
<ImageDocID>12481</ImageDocID>
<Gender>DR</Gender>
<Amount>1733.06</Amount>
<TC/>
<AN>1002419133</AN>
<Fld4/>
<RT>043301627</RT>
<RIC/>
<Aux>0013866851</Aux>
<ACHCode>Check21</ACHCode>
<ACHConvertedRT/>
<ACHConvertedAccount/>
<IsElectronic>FALSE</IsElectronic>
<IsOnUs>FALSE</IsOnUs>
<IsDeleted>FALSE</IsDeleted>
<IsInsert>FALSE</IsInsert>
<IsCorrected>FALSE</IsCorrected>
<IsReject>FALSE</IsReject>
<RejectReason>0</RejectReason>
<OutsortReason>0</OutsortReason>
<Availability>0</Availability>
<AppCode>0</AppCode>
<SPSelector>8000</SPSelector>
<Currency>USD</Currency>
<AdjustmentType>0</AdjustmentType>
<AdjustmentReason>0</AdjustmentReason>
<Images>
<Image>
<ImageView>Front</ImageView>
<ImageType>CCITTG4</ImageType>
<ImageOffSet>19370</ImageOffSet>
<ImageLength>10443</ImageLength>
</Image>
<Image>
<ImageView>Rear</ImageView>
<ImageType>CCITTG4</ImageType>
<ImageOffSet>12719</ImageOffSet>
<ImageLength>5143</ImageLength>
</Image>
</Images>
<CustomerUserInfo>
<Field1>o0013866851ot043301627t1002419133o</Field1>
<Field2>8000</Field2>
<Field3/>
<Field4>0011000110000000000000000</Field4>
</CustomerUserInfo>
</Item>
<Item>
<ISN>790100007 </ISN>
<ImageDocID>12482</ImageDocID>
<Gender>DR</Gender>
<Amount>10672.12</Amount>
<TC/>
<AN>009000091</AN>
<Fld4/>
<RT>999999999</RT>
<RIC/>
<Aux>1095468</Aux>
<ACHCode>Check21</ACHCode>
<ACHConvertedRT/>
<ACHConvertedAccount/>
<IsElectronic>FALSE</IsElectronic>
<IsOnUs>FALSE</IsOnUs>
<IsDeleted>FALSE</IsDeleted>
<IsInsert>FALSE</IsInsert>
<IsCorrected>FALSE</IsCorrected>
<IsReject>FALSE</IsReject>
<RejectReason>0</RejectReason>
<OutsortReason>0</OutsortReason>
<Availability>0</Availability>
<AppCode>0</AppCode>
<SPSelector>8000</SPSelector>
<Currency>USD</Currency>
<AdjustmentType>0</AdjustmentType>
<AdjustmentReason>0</AdjustmentReason>
<Images>
<Image>
<ImageView>Front</ImageView>
<ImageType>CCITTG4</ImageType>
<ImageOffSet>29813</ImageOffSet>
<ImageLength>22934</ImageLength>
</Image>
<Image>
<ImageView>Rear</ImageView>
<ImageType>CCITTG4</ImageType>
<ImageOffSet>17862</ImageOffSet>
<ImageLength>18116</ImageLength>
</Image>
</Images>
<CustomerUserInfo>
<Field1>o1095468ot031301422t009000091o</Field1>
<Field2>8000</Field2>
<Field3/>
<Field4>0011000110000000000000000</Field4>
</CustomerUserInfo>
</Item>
<Item>
<ISN>790100008 </ISN>
<ImageDocID>12483</ImageDocID>
<Gender>CR</Gender>
<Amount>208000.00</Amount>
<TC>009</TC>
<AN>0100000140</AN>
<Fld4/>
<RT>031919186</RT>
<RIC/>
<Aux>000033</Aux>
<ACHCode>Check21</ACHCode>
<ACHConvertedRT/>
<ACHConvertedAccount/>
<IsElectronic>FALSE</IsElectronic>
<IsOnUs>TRUE</IsOnUs>
<IsDeleted>FALSE</IsDeleted>
<IsInsert>FALSE</IsInsert>
<IsCorrected>FALSE</IsCorrected>
<IsReject>FALSE</IsReject>
<RejectReason>0</RejectReason>
<OutsortReason>0</OutsortReason>
<Availability>0</Availability>
<AppCode>0</AppCode>
<SPSelector>1000</SPSelector>
<Currency>USD</Currency>
<AdjustmentType>0</AdjustmentType>
<AdjustmentReason>0</AdjustmentReason>
<Images>
<Image>
<ImageView>Front</ImageView>
<ImageType>CCITTG4</ImageType>
<ImageOffSet>52747</ImageOffSet>
<ImageLength>6116</ImageLength>
</Image>
<Image>
<ImageView>Rear</ImageView>
<ImageType>CCITTG4</ImageType>
<ImageOffSet>35978</ImageOffSet>
<ImageLength>3103</ImageLength>
</Image>
</Images>
<CustomerUserInfo>
<Field1>o000033ot031919186t0100000140o009</Field1>
<Field2>1001</Field2>
<Field3/>
<Field4>0011000110000000000000000</Field4>
</CustomerUserInfo>
</Item>
<Item>
<ISN>790100009 </ISN>
<ImageDocID>12484</ImageDocID>
<Gender>DR</Gender>
<Amount>208000.00</Amount>
<TC>500</TC>
<AN>1390050098</AN>
<Fld4/>
<RT>5021-1000</RT>
<RIC/>
<Aux/>
<ACHCode>Check21</ACHCode>
<ACHConvertedRT/>
<ACHConvertedAccount/>
<IsElectronic>FALSE</IsElectronic>
<IsOnUs>TRUE</IsOnUs>
<IsDeleted>FALSE</IsDeleted>
<IsInsert>FALSE</IsInsert>
<IsCorrected>FALSE</IsCorrected>
<IsReject>FALSE</IsReject>
<RejectReason>0</RejectReason>
<OutsortReason>0</OutsortReason>
<Availability>0</Availability>
<AppCode>0</AppCode>
<SPSelector>2000</SPSelector>
<Currency>USD</Currency>
<AdjustmentType>0</AdjustmentType>
<AdjustmentReason>0</AdjustmentReason>
<Images>
<Image>
<ImageView>Front</ImageView>
<ImageType>CCITTG4</ImageType>
<ImageOffSet>58863</ImageOffSet>
<ImageLength>5649</ImageLength>
</Image>
<Image>
<ImageView>Rear</ImageView>
<ImageType>CCITTG4</ImageType>
<ImageOffSet>39081</ImageOffSet>
<ImageLength>1620</ImageLength>
</Image>
</Images>
<CustomerUserInfo>
<Field1>t5021-1000t500</Field1>
<Field2>2006</Field2>
<Field3/>
<Field4/>
</CustomerUserInfo>
</Item>
<Item>
<ISN>790100010 </ISN>
<ImageDocID>12485</ImageDocID>
<Gender>CR</Gender>
<Amount>5626.06</Amount>
<TC>009</TC>
<AN>040000134</AN>
<Fld4/>
<RT>5300-1000</RT>
<RIC/>
<Aux/>
<ACHCode>Check21</ACHCode>
<ACHConvertedRT/>
<ACHConvertedAccount/>
<IsElectronic>FALSE</IsElectronic>
<IsOnUs>TRUE</IsOnUs>
<IsDeleted>FALSE</IsDeleted>
<IsInsert>FALSE</IsInsert>
<IsCorrected>FALSE</IsCorrected>
<IsReject>FALSE</IsReject>
<RejectReason>0</RejectReason>
<OutsortReason>0</OutsortReason>
<Availability>0</Availability>
<AppCode>0</AppCode>
<SPSelector>1000</SPSelector>
<Currency>USD</Currency>
<AdjustmentType>0</AdjustmentType>
<AdjustmentReason>0</AdjustmentReason>
<Images>
<Image>
<ImageView>Front</ImageView>
<ImageType>CCITTG4</ImageType>
<ImageOffSet>64512</ImageOffSet>
<ImageLength>4797</ImageLength>
</Image>
<Image>
<ImageView>Rear</ImageView>
<ImageType>CCITTG4</ImageType>
<ImageOffSet>40701</ImageOffSet>
<ImageLength>4756</ImageLength>
</Image>
</Images>
<CustomerUserInfo>
<Field1>t5300-1000t</Field1>
<Field2>1001</Field2>
<Field3/>
<Field4/>
</CustomerUserInfo>
</Item>
<Item>
<ISN>790100054 </ISN>
<ImageDocID>12527</ImageDocID>
<Gender>CR</Gender>
<Amount>150.00</Amount>
<TC>400</TC>
<AN>7820000001</AN>
<Fld4/>
<RT>5020-1000</RT>
<RIC/>
<Aux/>
<ACHCode>Check21</ACHCode>
<ACHConvertedRT/>
<ACHConvertedAccount/>
<IsElectronic>FALSE</IsElectronic>
<IsOnUs>TRUE</IsOnUs>
<IsDeleted>FALSE</IsDeleted>
<IsInsert>FALSE</IsInsert>
<IsCorrected>FALSE</IsCorrected>
<IsReject>FALSE</IsReject>
<RejectReason>0</RejectReason>
<OutsortReason>0</OutsortReason>
<Availability>0</Availability>
<AppCode>0</AppCode>
<SPSelector>1000</SPSelector>
<Currency>USD</Currency>
<AdjustmentType>0</AdjustmentType>
<AdjustmentReason>0</AdjustmentReason>
<Images>
<Image>
<ImageView>Front</ImageView>
<ImageType>CCITTG4</ImageType>
<ImageOffSet>449337</ImageOffSet>
<ImageLength>5384</ImageLength>
</Image>
<Image>
<ImageView>Rear</ImageView>
<ImageType>CCITTG4</ImageType>
<ImageOffSet>250370</ImageOffSet>
<ImageLength>1684</ImageLength>
</Image>
</Images>
<CustomerUserInfo>
<Field1>t5020-1000t400</Field1>
<Field2>1006</Field2>
<Field3/>
<Field4/>
</CustomerUserInfo>
</Item>
<Item>
<ISN>790100055 </ISN>
<ImageDocID>12528</ImageDocID>
<Gender>DR</Gender>
<Amount>150.00</Amount>
<TC>700</TC>
<AN>1001010001</AN>
<Fld4/>
<RT>5011-0000</RT>
<RIC/>
<Aux/>
<ACHCode>Check21</ACHCode>
<ACHConvertedRT/>
<ACHConvertedAccount/>
<IsElectronic>FALSE</IsElectronic>
<IsOnUs>TRUE</IsOnUs>
<IsDeleted>FALSE</IsDeleted>
<IsInsert>FALSE</IsInsert>
<IsCorrected>FALSE</IsCorrected>
<IsReject>FALSE</IsReject>
<RejectReason>0</RejectReason>
<OutsortReason>0</OutsortReason>
<Availability>0</Availability>
<AppCode>0</AppCode>
<SPSelector>2000</SPSelector>
<Currency>USD</Currency>
<AdjustmentType>0</AdjustmentType>
<AdjustmentReason>0</AdjustmentReason>
<Images>
<Image>
<ImageView>Front</ImageView>
<ImageType>CCITTG4</ImageType>
<ImageOffSet>454721</ImageOffSet>
<ImageLength>2196</ImageLength>
</Image>
<Image>
<ImageView>Rear</ImageView>
<ImageType>CCITTG4</ImageType>
<ImageOffSet>252054</ImageOffSet>
<ImageLength>1734</ImageLength>
</Image>
</Images>
<CustomerUserInfo>
<Field1>t5011-0000t1001010001o700</Field1>
<Field2>2006</Field2>
<Field3/>
<Field4/>
</CustomerUserInfo>
</Item>
<Item>
<ISN>790100056 </ISN>
<ImageDocID>12529</ImageDocID>
<Gender>CR</Gender>
<Amount>11190.15</Amount>
<TC>009</TC>
<AN>0120000773</AN>
<Fld4/>
<RT>5300-1000</RT>
<RIC/>
<Aux/>
<ACHCode>Check21</ACHCode>
<ACHConvertedRT/>
<ACHConvertedAccount/>
<IsElectronic>FALSE</IsElectronic>
<IsOnUs>TRUE</IsOnUs>
<IsDeleted>FALSE</IsDeleted>
<IsInsert>FALSE</IsInsert>
<IsCorrected>FALSE</IsCorrected>
<IsReject>FALSE</IsReject>
<RejectReason>0</RejectReason>
<OutsortReason>0</OutsortReason>
<Availability>0</Availability>
<AppCode>0</AppCode>
<SPSelector>1000</SPSelector>
<Currency>USD</Currency>
<AdjustmentType>0</AdjustmentType>
<AdjustmentReason>0</AdjustmentReason>
<Images>
<Image>
<ImageView>Front</ImageView>
<ImageType>CCITTG4</ImageType>
<ImageOffSet>456917</ImageOffSet>
<ImageLength>4335</ImageLength>
</Image>
<Image>
<ImageView>Rear</ImageView>
<ImageType>CCITTG4</ImageType>
<ImageOffSet>253788</ImageOffSet>
<ImageLength>4101</ImageLength>
</Image>
</Images>
<CustomerUserInfo>
<Field1>t5300-1000t009</Field1>
<Field2>1001</Field2>
<Field3/>
<Field4/>
</CustomerUserInfo>
</Item>
<Item>
<ISN>790100057 </ISN>
<ImageDocID>12530</ImageDocID>
<Gender>DR</Gender>
<Amount>11190.15</Amount>
<TC/>
<AN>68001764644391</AN>
<Fld4/>
<RT>102000979</RT>
<RIC/>
<Aux>225127</Aux>
<ACHCode>Check21</ACHCode>
<ACHConvertedRT/>
<ACHConvertedAccount/>
<IsElectronic>FALSE</IsElectronic>
<IsOnUs>FALSE</IsOnUs>
<IsDeleted>FALSE</IsDeleted>
<IsInsert>FALSE</IsInsert>
<IsCorrected>FALSE</IsCorrected>
<IsReject>FALSE</IsReject>
<RejectReason>0</RejectReason>
<OutsortReason>0</OutsortReason>
<Availability>0</Availability>
<AppCode>0</AppCode>
<SPSelector>8000</SPSelector>
<Currency>USD</Currency>
<AdjustmentType>0</AdjustmentType>
<AdjustmentReason>0</AdjustmentReason>
<Images>
<Image>
<ImageView>Front</ImageView>
<ImageType>CCITTG4</ImageType>
<ImageOffSet>461252</ImageOffSet>
<ImageLength>17986</ImageLength>
</Image>
<Image>
<ImageView>Rear</ImageView>
<ImageType>CCITTG4</ImageType>
<ImageOffSet>257889</ImageOffSet>
<ImageLength>8432</ImageLength>
</Image>
</Images>
<CustomerUserInfo>
<Field1>o225127ot102000979t68001764644391o</Field1>
<Field2>8000</Field2>
<Field3/>
<Field4>0011000110000000000000000</Field4>
</CustomerUserInfo>
</Item>
<Item>
<ISN>790100058 </ISN>
<ImageDocID>12531</ImageDocID>
<Gender>DR</Gender>
<Amount>100.00</Amount>
<TC>1436</TC>
<AN>004969395616</AN>
<Fld4/>
<RT>122400724</RT>
<RIC/>
<Aux/>
<ACHCode>Check21</ACHCode>
<ACHConvertedRT/>
<ACHConvertedAccount/>
<IsElectronic>FALSE</IsElectronic>
<IsOnUs>FALSE</IsOnUs>
<IsDeleted>TRUE</IsDeleted>
<IsInsert>FALSE</IsInsert>
<IsCorrected>FALSE</IsCorrected>
<IsReject>FALSE</IsReject>
<RejectReason>0</RejectReason>
<OutsortReason>0</OutsortReason>
<Availability>0</Availability>
<AppCode>0</AppCode>
<SPSelector>8000</SPSelector>
<Currency>USD</Currency>
<AdjustmentType>0</AdjustmentType>
<AdjustmentReason>0</AdjustmentReason>
<Images>
<Image>
<ImageView>Front</ImageView>
<ImageType>CCITTG4</ImageType>
<ImageOffSet>479238</ImageOffSet>
<ImageLength>13393</ImageLength>
</Image>
<Image>
<ImageView>Rear</ImageView>
<ImageType>CCITTG4</ImageType>
<ImageOffSet>266321</ImageOffSet>
<ImageLength>2824</ImageLength>
</Image>
</Images>
<CustomerUserInfo>
<Field1>t122400724t004969395616o1436</Field1>
<Field2>8000</Field2>
<Field3/>
<Field4>0011000110000000000000000</Field4>
</CustomerUserInfo>
</Item>
<Item>
<ISN>790100059 </ISN>
<ImageDocID>12532</ImageDocID>
<Gender>CR</Gender>
<Amount>350000.00</Amount>
<TC>009</TC>
<AN>0100000140</AN>
<Fld4/>
<RT>031919186</RT>
<RIC/>
<Aux>000035</Aux>
<ACHCode>Check21</ACHCode>
<ACHConvertedRT/>
<ACHConvertedAccount/>
<IsElectronic>FALSE</IsElectronic>
<IsOnUs>TRUE</IsOnUs>
<IsDeleted>FALSE</IsDeleted>
<IsInsert>FALSE</IsInsert>
<IsCorrected>FALSE</IsCorrected>
<IsReject>FALSE</IsReject>
<RejectReason>0</RejectReason>
<OutsortReason>0</OutsortReason>
<Availability>0</Availability>
<AppCode>0</AppCode>
<SPSelector>1000</SPSelector>
<Currency>USD</Currency>
<AdjustmentType>0</AdjustmentType>
<AdjustmentReason>0</AdjustmentReason>
<Images>
<Image>
<ImageView>Front</ImageView>
<ImageType>CCITTG4</ImageType>
<ImageOffSet>492631</ImageOffSet>
<ImageLength>5447</ImageLength>
</Image>
<Image>
<ImageView>Rear</ImageView>
<ImageType>CCITTG4</ImageType>
<ImageOffSet>269145</ImageOffSet>
<ImageLength>3026</ImageLength>
</Image>
</Images>
<CustomerUserInfo>
<Field1>o000035ot031919186t0100000140o009</Field1>
<Field2>1001</Field2>
<Field3/>
<Field4>0011000110000000000000000</Field4>
</CustomerUserInfo>
</Item>
<Item>
<ISN>790100060 </ISN>
<ImageDocID>12533</ImageDocID>
<Gender>DR</Gender>
<Amount>350000.00</Amount>
<TC>500</TC>
<AN>1390050098</AN>
<Fld4/>
<RT>5021-1000</RT>
<RIC/>
<Aux/>
<ACHCode>Check21</ACHCode>
<ACHConvertedRT/>
<ACHConvertedAccount/>
<IsElectronic>FALSE</IsElectronic>
<IsOnUs>TRUE</IsOnUs>
<IsDeleted>FALSE</IsDeleted>
<IsInsert>FALSE</IsInsert>
<IsCorrected>FALSE</IsCorrected>
<IsReject>FALSE</IsReject>
<RejectReason>0</RejectReason>
<OutsortReason>0</OutsortReason>
<Availability>0</Availability>
<AppCode>0</AppCode>
<SPSelector>2000</SPSelector>
<Currency>USD</Currency>
<AdjustmentType>0</AdjustmentType>
<AdjustmentReason>0</AdjustmentReason>
<Images>
<Image>
<ImageView>Front</ImageView>
<ImageType>CCITTG4</ImageType>
<ImageOffSet>498078</ImageOffSet>
<ImageLength>6115</ImageLength>
</Image>
<Image>
<ImageView>Rear</ImageView>
<ImageType>CCITTG4</ImageType>
<ImageOffSet>272171</ImageOffSet>
<ImageLength>1578</ImageLength>
</Image>
</Images>
<CustomerUserInfo>
<Field1>t5021-1000t500</Field1>
<Field2>2006</Field2>
<Field3/>
<Field4/>
</CustomerUserInfo>
</Item>
<Item>
<ISN>790100061 </ISN>
<ImageDocID>12534</ImageDocID>
<Gender>CR</Gender>
<Amount>1750.00</Amount>
<TC>400</TC>
<AN>1770010098</AN>
<Fld4/>
<RT>5020-1000</RT>
<RIC/>
<Aux/>
<ACHCode>Check21</ACHCode>
<ACHConvertedRT/>
<ACHConvertedAccount/>
<IsElectronic>FALSE</IsElectronic>
<IsOnUs>TRUE</IsOnUs>
<IsDeleted>FALSE</IsDeleted>
<IsInsert>FALSE</IsInsert>
<IsCorrected>FALSE</IsCorrected>
<IsReject>FALSE</IsReject>
<RejectReason>0</RejectReason>
<OutsortReason>0</OutsortReason>
<Availability>0</Availability>
<AppCode>0</AppCode>
<SPSelector>1000</SPSelector>
<Currency>USD</Currency>
<AdjustmentType>0</AdjustmentType>
<AdjustmentReason>0</AdjustmentReason>
<Images>
<Image>
<ImageView>Front</ImageView>
<ImageType>CCITTG4</ImageType>
<ImageOffSet>504193</ImageOffSet>
<ImageLength>5650</ImageLength>
</Image>
<Image>
<ImageView>Rear</ImageView>
<ImageType>CCITTG4</ImageType>
<ImageOffSet>273749</ImageOffSet>
<ImageLength>2963</ImageLength>
</Image>
</Images>
<CustomerUserInfo>
<Field1>t5020-1000t400</Field1>
<Field2>1006</Field2>
<Field3/>
<Field4/>
</CustomerUserInfo>
</Item>
<Item>
<ISN>790100062 </ISN>
<ImageDocID>12535</ImageDocID>
<Gender>DR</Gender>
<Amount>1750.00</Amount>
<TC/>
<AN>2000012542651</AN>
<Fld4/>
<RT>031000503</RT>
<RIC/>
<Aux>017371</Aux>
<ACHCode>Check21</ACHCode>
<ACHConvertedRT/>
<ACHConvertedAccount/>
<IsElectronic>FALSE</IsElectronic>
<IsOnUs>FALSE</IsOnUs>
<IsDeleted>FALSE</IsDeleted>
<IsInsert>FALSE</IsInsert>
<IsCorrected>FALSE</IsCorrected>
<IsReject>FALSE</IsReject>
<RejectReason>0</RejectReason>
<OutsortReason>0</OutsortReason>
<Availability>0</Availability>
<AppCode>0</AppCode>
<SPSelector>8000</SPSelector>
<Currency>USD</Currency>
<AdjustmentType>0</AdjustmentType>
<AdjustmentReason>0</AdjustmentReason>
<Images>
<Image>
<ImageView>Front</ImageView>
<ImageType>CCITTG4</ImageType>
<ImageOffSet>509843</ImageOffSet>
<ImageLength>10988</ImageLength>
</Image>
<Image>
<ImageView>Rear</ImageView>
<ImageType>CCITTG4</ImageType>
<ImageOffSet>276712</ImageOffSet>
<ImageLength>2374</ImageLength>
</Image>
</Images>
<CustomerUserInfo>
<Field1>o017371ot031000503t2000012542651o</Field1>
<Field2>8000</Field2>
<Field3/>
<Field4>0011000110000000000000000</Field4>
</CustomerUserInfo>
</Item>
<Item>
<ISN>790100063 </ISN>
<ImageDocID>12536</ImageDocID>
<Gender>CR</Gender>
<Amount>60.00</Amount>
<TC>600</TC>
<AN>1001010001</AN>
<Fld4/>
<RT>5010-0000</RT>
<RIC/>
<Aux/>
<ACHCode>Check21</ACHCode>
<ACHConvertedRT/>
<ACHConvertedAccount/>
<IsElectronic>FALSE</IsElectronic>
<IsOnUs>TRUE</IsOnUs>
<IsDeleted>FALSE</IsDeleted>
<IsInsert>FALSE</IsInsert>
<IsCorrected>FALSE</IsCorrected>
<IsReject>FALSE</IsReject>
<RejectReason>0</RejectReason>
<OutsortReason>0</OutsortReason>
<Availability>0</Availability>
<AppCode>0</AppCode>
<SPSelector>1000</SPSelector>
<Currency>USD</Currency>
<AdjustmentType>0</AdjustmentType>
<AdjustmentReason>0</AdjustmentReason>
<Images>
<Image>
<ImageView>Front</ImageView>
<ImageType>CCITTG4</ImageType>
<ImageOffSet>520831</ImageOffSet>
<ImageLength>2654</ImageLength>
</Image>
<Image>
<ImageView>Rear</ImageView>
<ImageType>CCITTG4</ImageType>
<ImageOffSet>279086</ImageOffSet>
<ImageLength>2314</ImageLength>
</Image>
</Images>
<CustomerUserInfo>
<Field1>t5010-0000t1001010001o600</Field1>
<Field2>1006</Field2>
<Field3/>
<Field4/>
</CustomerUserInfo>
</Item>
<Item>
<ISN>790100064 </ISN>
<ImageDocID>12537</ImageDocID>
<Gender>DR</Gender>
<Amount>60.00</Amount>
<TC>046</TC>
<AN>0120000104</AN>
<Fld4/>
<RT>5301-1000</RT>
<RIC/>
<Aux/>
<ACHCode>Check21</ACHCode>
<ACHConvertedRT/>
<ACHConvertedAccount/>
<IsElectronic>FALSE</IsElectronic>
<IsOnUs>TRUE</IsOnUs>
<IsDeleted>FALSE</IsDeleted>
<IsInsert>FALSE</IsInsert>
<IsCorrected>FALSE</IsCorrected>
<IsReject>FALSE</IsReject>
<RejectReason>0</RejectReason>
<OutsortReason>0</OutsortReason>
<Availability>0</Availability>
<AppCode>0</AppCode>
<SPSelector>2000</SPSelector>
<Currency>USD</Currency>
<AdjustmentType>0</AdjustmentType>
<AdjustmentReason>0</AdjustmentReason>
<Images>
<Image>
<ImageView>Front</ImageView>
<ImageType>CCITTG4</ImageType>
<ImageOffSet>523485</ImageOffSet>
<ImageLength>3894</ImageLength>
</Image>
<Image>
<ImageView>Rear</ImageView>
<ImageType>CCITTG4</ImageType>
<ImageOffSet>281400</ImageOffSet>
<ImageLength>2795</ImageLength>
</Image>
</Images>
<CustomerUserInfo>
<Field1>t5301-1000t046</Field1>
<Field2>2001</Field2>
<Field3/>
<Field4/>
</CustomerUserInfo>
</Item>
</Items>
</Batch>
</Batches>
<BatchCount>1</BatchCount>
</Block>
</Blocks>
<BlockCount>1</BlockCount>
</Job>
</Jobs>
</FileExchange>

Jun 27 '08 #1
  • viewed: 2696
Share:
6 Replies
If you can convert it into a dataset, then you can easily bind to it and do
usual DB type stuff with its values

http://devpinoy.org/blogs/keithrull/...o-dataset.aspx

http://www.ddj.com/windows/184416669
Regards

John Timney (MVP)
http://www.johntimney.com
http://www.johntimney.com/blog

"DavidM" <Da****@discussions.microsoft.comwrote in message
news:6B**********************************@microsof t.com...
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 file, then spit out
totals.

Since I haven't worked with XML too much in C#, I'm trying to develop a
structured and easy-to-read way to parse the file.

Essentially, I would like to read the file and add the "BatchTktAmount>
for
any <Batchelements that may exist. There could be 1 or more...

As a verification, I may also want to add the <BATCH\Itemselements,
there
could be 1 or more, and if <Genderis a credit "CR", accumulate totals
for
credit items. If <Genderis a debit "DR", acculate totals for debit
items.

Total items should equal the total batches.

I guess if I had relatively good XML parsing code, I could figure out how
to
read the file in such a way to get the information. The real kicker for
me
is the multiple batches and items.

Sample is below.

Any help would be appreciated

<FileExchange>
<Version>
<MajorVer>1</MajorVer>
<MinorVer>0</MinorVer>
</Version>
<Jobs>
<Job>
<StartTime>20080610:171706</StartTime>
<EndTime>20080610:171747</EndTime>
<BusinessDate>20080610</BusinessDate>
<Device>26</Device>
<Site/>
<ProcType>Prime</ProcType>
<WorkTypeNumber>1</WorkTypeNumber>
<ClearingType>OutClearing</ClearingType>
<DebitsFirst>FALSE</DebitsFirst>
<SortFamily>900</SortFamily>
<Imaged>TRUE</Imaged>
<NbrOfBlocksInJob>1</NbrOfBlocksInJob>
<CycleID>A</CycleID>
<Blocks>
<Block>
<BlkNbr>64</BlkNbr>
<BlkStartTime>20080610:171706</BlkStartTime>
<BlkEndTime>20080610:171747</BlkEndTime>
<BlkSeqInJob>1</BlkSeqInJob>
<BlkFrontImgFileName>\\VMSERVER1\MyApp\AllItemsExt ract\G179BC\0064_5.fim</BlkFrontImgFileName>
<BlkRearImgFileName>\\VMSERVER1\MyApp\AllItemsExtr act\G179BC\0064_5.rim</BlkRearImgFileName>
<Batches>
<Batch>
<BatchNbr>1</BatchNbr>
<BranchData>
<BranchID>079010</BranchID>
<BranchDeviceID>79010</BranchDeviceID>
<BranchTill>0</BranchTill>
<BranchBatchNbr>1</BranchBatchNbr>
<BranchBusinessDate>20080610</BranchBusinessDate>
</BranchData>
<BatchTktAmount>617181.39</BatchTktAmount>
<BatchTktTC/>
<BatchTktAN/>
<BatchTktRT>444444442</BatchTktRT>
<BatchTktAux/>
<Items>
<Item>
<ISN>790100003 </ISN>
<ImageDocID>12478</ImageDocID>
<Gender>CR</Gender>
<Amount>17000.00</Amount>
<TC>009</TC>
<AN>0120000153</AN>
<Fld4/>
<RT>5300-1000</RT>
<RIC/>
<Aux/>
<ACHCode>Check21</ACHCode>
<ACHConvertedRT/>
<ACHConvertedAccount/>
<IsElectronic>FALSE</IsElectronic>
<IsOnUs>TRUE</IsOnUs>
<IsDeleted>FALSE</IsDeleted>
<IsInsert>FALSE</IsInsert>
<IsCorrected>FALSE</IsCorrected>
<IsReject>FALSE</IsReject>
<RejectReason>0</RejectReason>
<OutsortReason>0</OutsortReason>
<Availability>0</Availability>
<AppCode>0</AppCode>
<SPSelector>1000</SPSelector>
<Currency>USD</Currency>
<AdjustmentType>0</AdjustmentType>
<AdjustmentReason>0</AdjustmentReason>
<Images>
<Image>
<ImageView>Front</ImageView>
<ImageType>CCITTG4</ImageType>
<ImageOffSet>514</ImageOffSet>
<ImageLength>6298</ImageLength>
</Image>
<Image>
<ImageView>Rear</ImageView>
<ImageType>CCITTG4</ImageType>
<ImageOffSet>514</ImageOffSet>
<ImageLength>5240</ImageLength>
</Image>
</Images>
<CustomerUserInfo>
<Field1>t5300-1000t0120000153o009</Field1>
<Field2>1001</Field2>
<Field3/>
<Field4/>
</CustomerUserInfo>
</Item>
<Item>
<ISN>790100004 </ISN>
<ImageDocID>12479</ImageDocID>
<Gender>DR</Gender>
<Amount>17000.00</Amount>
<TC>1011</TC>
<AN>362343062</AN>
<Fld4/>
<RT>999999999</RT>
<RIC/>
<Aux/>
<ACHCode>Check21</ACHCode>
<ACHConvertedRT/>
<ACHConvertedAccount/>
<IsElectronic>FALSE</IsElectronic>
<IsOnUs>FALSE</IsOnUs>
<IsDeleted>FALSE</IsDeleted>
<IsInsert>FALSE</IsInsert>
<IsCorrected>FALSE</IsCorrected>
<IsReject>FALSE</IsReject>
<RejectReason>0</RejectReason>
<OutsortReason>0</OutsortReason>
<Availability>0</Availability>
<AppCode>0</AppCode>
<SPSelector>8000</SPSelector>
<Currency>USD</Currency>
<AdjustmentType>0</AdjustmentType>
<AdjustmentReason>0</AdjustmentReason>
<Images>
<Image>
<ImageView>Front</ImageView>
<ImageType>CCITTG4</ImageType>
<ImageOffSet>6812</ImageOffSet>
<ImageLength>7624</ImageLength>
</Image>
<Image>
<ImageView>Rear</ImageView>
<ImageType>CCITTG4</ImageType>
<ImageOffSet>5754</ImageOffSet>
<ImageLength>2820</ImageLength>
</Image>
</Images>
<CustomerUserInfo>
<Field1>t031301422t362343062o1011</Field1>
<Field2>8000</Field2>
<Field3/>
<Field4>0011000110000000000000000</Field4>
</CustomerUserInfo>
</Item>
<Item>
<ISN>790100005 </ISN>
<ImageDocID>12480</ImageDocID>
<Gender>CR</Gender>
<Amount>12405.18</Amount>
<TC>109</TC>
<AN>014002437</AN>
<Fld4/>
<RT>5009-1000</RT>
<RIC/>
<Aux/>
<ACHCode>Check21</ACHCode>
<ACHConvertedRT/>
<ACHConvertedAccount/>
<IsElectronic>FALSE</IsElectronic>
<IsOnUs>TRUE</IsOnUs>
<IsDeleted>FALSE</IsDeleted>
<IsInsert>FALSE</IsInsert>
<IsCorrected>FALSE</IsCorrected>
<IsReject>FALSE</IsReject>
<RejectReason>0</RejectReason>
<OutsortReason>0</OutsortReason>
<Availability>0</Availability>
<AppCode>0</AppCode>
<SPSelector>1000</SPSelector>
<Currency>USD</Currency>
<AdjustmentType>0</AdjustmentType>
<AdjustmentReason>0</AdjustmentReason>
<Images>
<Image>
<ImageView>Front</ImageView>
<ImageType>CCITTG4</ImageType>
<ImageOffSet>14436</ImageOffSet>
<ImageLength>4934</ImageLength>
</Image>
<Image>
<ImageView>Rear</ImageView>
<ImageType>CCITTG4</ImageType>
<ImageOffSet>8574</ImageOffSet>
<ImageLength>4145</ImageLength>
</Image>
</Images>
<CustomerUserInfo>
<Field1>t5009-1000t109</Field1>
<Field2>1003</Field2>
<Field3/>
<Field4/>
</CustomerUserInfo>
</Item>
<Item>
<ISN>790100006 </ISN>
<ImageDocID>12481</ImageDocID>
<Gender>DR</Gender>
<Amount>1733.06</Amount>
<TC/>
<AN>1002419133</AN>
<Fld4/>
<RT>043301627</RT>
<RIC/>
<Aux>0013866851</Aux>
<ACHCode>Check21</ACHCode>
<ACHConvertedRT/>
<ACHConvertedAccount/>
<IsElectronic>FALSE</IsElectronic>
<IsOnUs>FALSE</IsOnUs>
<IsDeleted>FALSE</IsDeleted>
<IsInsert>FALSE</IsInsert>
<IsCorrected>FALSE</IsCorrected>
<IsReject>FALSE</IsReject>
<RejectReason>0</RejectReason>
<OutsortReason>0</OutsortReason>
<Availability>0</Availability>
<AppCode>0</AppCode>
<SPSelector>8000</SPSelector>
<Currency>USD</Currency>
<AdjustmentType>0</AdjustmentType>
<AdjustmentReason>0</AdjustmentReason>
<Images>
<Image>
<ImageView>Front</ImageView>
<ImageType>CCITTG4</ImageType>
<ImageOffSet>19370</ImageOffSet>
<ImageLength>10443</ImageLength>
</Image>
<Image>
<ImageView>Rear</ImageView>
<ImageType>CCITTG4</ImageType>
<ImageOffSet>12719</ImageOffSet>
<ImageLength>5143</ImageLength>
</Image>
</Images>
<CustomerUserInfo>
<Field1>o0013866851ot043301627t1002419133o</Field1>
<Field2>8000</Field2>
<Field3/>
<Field4>0011000110000000000000000</Field4>
</CustomerUserInfo>
</Item>
<Item>
<ISN>790100007 </ISN>
<ImageDocID>12482</ImageDocID>
<Gender>DR</Gender>
<Amount>10672.12</Amount>
<TC/>
<AN>009000091</AN>
<Fld4/>
<RT>999999999</RT>
<RIC/>
<Aux>1095468</Aux>
<ACHCode>Check21</ACHCode>
<ACHConvertedRT/>
<ACHConvertedAccount/>
<IsElectronic>FALSE</IsElectronic>
<IsOnUs>FALSE</IsOnUs>
<IsDeleted>FALSE</IsDeleted>
<IsInsert>FALSE</IsInsert>
<IsCorrected>FALSE</IsCorrected>
<IsReject>FALSE</IsReject>
<RejectReason>0</RejectReason>
<OutsortReason>0</OutsortReason>
<Availability>0</Availability>
<AppCode>0</AppCode>
<SPSelector>8000</SPSelector>
<Currency>USD</Currency>
<AdjustmentType>0</AdjustmentType>
<AdjustmentReason>0</AdjustmentReason>
<Images>
<Image>
<ImageView>Front</ImageView>
<ImageType>CCITTG4</ImageType>
<ImageOffSet>29813</ImageOffSet>
<ImageLength>22934</ImageLength>
</Image>
<Image>
<ImageView>Rear</ImageView>
<ImageType>CCITTG4</ImageType>
<ImageOffSet>17862</ImageOffSet>
<ImageLength>18116</ImageLength>
</Image>
</Images>
<CustomerUserInfo>
<Field1>o1095468ot031301422t009000091o</Field1>
<Field2>8000</Field2>
<Field3/>
<Field4>0011000110000000000000000</Field4>
</CustomerUserInfo>
</Item>
<Item>
<ISN>790100008 </ISN>
<ImageDocID>12483</ImageDocID>
<Gender>CR</Gender>
<Amount>208000.00</Amount>
<TC>009</TC>
<AN>0100000140</AN>
<Fld4/>
<RT>031919186</RT>
<RIC/>
<Aux>000033</Aux>
<ACHCode>Check21</ACHCode>
<ACHConvertedRT/>
<ACHConvertedAccount/>
<IsElectronic>FALSE</IsElectronic>
<IsOnUs>TRUE</IsOnUs>
<IsDeleted>FALSE</IsDeleted>
<IsInsert>FALSE</IsInsert>
<IsCorrected>FALSE</IsCorrected>
<IsReject>FALSE</IsReject>
<RejectReason>0</RejectReason>
<OutsortReason>0</OutsortReason>
<Availability>0</Availability>
<AppCode>0</AppCode>
<SPSelector>1000</SPSelector>
<Currency>USD</Currency>
<AdjustmentType>0</AdjustmentType>
<AdjustmentReason>0</AdjustmentReason>
<Images>
<Image>
<ImageView>Front</ImageView>
<ImageType>CCITTG4</ImageType>
<ImageOffSet>52747</ImageOffSet>
<ImageLength>6116</ImageLength>
</Image>
<Image>
<ImageView>Rear</ImageView>
<ImageType>CCITTG4</ImageType>
<ImageOffSet>35978</ImageOffSet>
<ImageLength>3103</ImageLength>
</Image>
</Images>
<CustomerUserInfo>
<Field1>o000033ot031919186t0100000140o009</Field1>
<Field2>1001</Field2>
<Field3/>
<Field4>0011000110000000000000000</Field4>
</CustomerUserInfo>
</Item>
<Item>
<ISN>790100009 </ISN>
<ImageDocID>12484</ImageDocID>
<Gender>DR</Gender>
<Amount>208000.00</Amount>
<TC>500</TC>
<AN>1390050098</AN>
<Fld4/>
<RT>5021-1000</RT>
<RIC/>
<Aux/>
<ACHCode>Check21</ACHCode>
<ACHConvertedRT/>
<ACHConvertedAccount/>
<IsElectronic>FALSE</IsElectronic>
<IsOnUs>TRUE</IsOnUs>
<IsDeleted>FALSE</IsDeleted>
<IsInsert>FALSE</IsInsert>
<IsCorrected>FALSE</IsCorrected>
<IsReject>FALSE</IsReject>
<RejectReason>0</RejectReason>
<OutsortReason>0</OutsortReason>
<Availability>0</Availability>
<AppCode>0</AppCode>
<SPSelector>2000</SPSelector>
<Currency>USD</Currency>
<AdjustmentType>0</AdjustmentType>
<AdjustmentReason>0</AdjustmentReason>
<Images>
<Image>
<ImageView>Front</ImageView>
<ImageType>CCITTG4</ImageType>
<ImageOffSet>58863</ImageOffSet>
<ImageLength>5649</ImageLength>
</Image>
<Image>
<ImageView>Rear</ImageView>
<ImageType>CCITTG4</ImageType>
<ImageOffSet>39081</ImageOffSet>
<ImageLength>1620</ImageLength>
</Image>
</Images>
<CustomerUserInfo>
<Field1>t5021-1000t500</Field1>
<Field2>2006</Field2>
<Field3/>
<Field4/>
</CustomerUserInfo>
</Item>
<Item>
<ISN>790100010 </ISN>
<ImageDocID>12485</ImageDocID>
<Gender>CR</Gender>
<Amount>5626.06</Amount>
<TC>009</TC>
<AN>040000134</AN>
<Fld4/>
<RT>5300-1000</RT>
<RIC/>
<Aux/>
<ACHCode>Check21</ACHCode>
<ACHConvertedRT/>
<ACHConvertedAccount/>
<IsElectronic>FALSE</IsElectronic>
<IsOnUs>TRUE</IsOnUs>
<IsDeleted>FALSE</IsDeleted>
<IsInsert>FALSE</IsInsert>
<IsCorrected>FALSE</IsCorrected>
<IsReject>FALSE</IsReject>
<RejectReason>0</RejectReason>
<OutsortReason>0</OutsortReason>
<Availability>0</Availability>
<AppCode>0</AppCode>
<SPSelector>1000</SPSelector>
<Currency>USD</Currency>
<AdjustmentType>0</AdjustmentType>
<AdjustmentReason>0</AdjustmentReason>
<Images>
<Image>
<ImageView>Front</ImageView>
<ImageType>CCITTG4</ImageType>
<ImageOffSet>64512</ImageOffSet>
<ImageLength>4797</ImageLength>
</Image>
<Image>
<ImageView>Rear</ImageView>
<ImageType>CCITTG4</ImageType>
<ImageOffSet>40701</ImageOffSet>
<ImageLength>4756</ImageLength>
</Image>
</Images>
<CustomerUserInfo>
<Field1>t5300-1000t</Field1>
<Field2>1001</Field2>
<Field3/>
<Field4/>
</CustomerUserInfo>
</Item>
<Item>
<ISN>790100054 </ISN>
<ImageDocID>12527</ImageDocID>
<Gender>CR</Gender>
<Amount>150.00</Amount>
<TC>400</TC>
<AN>7820000001</AN>
<Fld4/>
<RT>5020-1000</RT>
<RIC/>
<Aux/>
<ACHCode>Check21</ACHCode>
<ACHConvertedRT/>
<ACHConvertedAccount/>
<IsElectronic>FALSE</IsElectronic>
<IsOnUs>TRUE</IsOnUs>
<IsDeleted>FALSE</IsDeleted>
<IsInsert>FALSE</IsInsert>
<IsCorrected>FALSE</IsCorrected>
<IsReject>FALSE</IsReject>
<RejectReason>0</RejectReason>
<OutsortReason>0</OutsortReason>
<Availability>0</Availability>
<AppCode>0</AppCode>
<SPSelector>1000</SPSelector>
<Currency>USD</Currency>
<AdjustmentType>0</AdjustmentType>
<AdjustmentReason>0</AdjustmentReason>
<Images>
<Image>
<ImageView>Front</ImageView>
<ImageType>CCITTG4</ImageType>
<ImageOffSet>449337</ImageOffSet>
<ImageLength>5384</ImageLength>
</Image>
<Image>
<ImageView>Rear</ImageView>
<ImageType>CCITTG4</ImageType>
<ImageOffSet>250370</ImageOffSet>
<ImageLength>1684</ImageLength>
</Image>
</Images>
<CustomerUserInfo>
<Field1>t5020-1000t400</Field1>
<Field2>1006</Field2>
<Field3/>
<Field4/>
</CustomerUserInfo>
</Item>
<Item>
<ISN>790100055 </ISN>
<ImageDocID>12528</ImageDocID>
<Gender>DR</Gender>
<Amount>150.00</Amount>
<TC>700</TC>
<AN>1001010001</AN>
<Fld4/>
<RT>5011-0000</RT>
<RIC/>
<Aux/>
<ACHCode>Check21</ACHCode>
<ACHConvertedRT/>
<ACHConvertedAccount/>
<IsElectronic>FALSE</IsElectronic>
<IsOnUs>TRUE</IsOnUs>
<IsDeleted>FALSE</IsDeleted>
<IsInsert>FALSE</IsInsert>
<IsCorrected>FALSE</IsCorrected>
<IsReject>FALSE</IsReject>
<RejectReason>0</RejectReason>
<OutsortReason>0</OutsortReason>
<Availability>0</Availability>
<AppCode>0</AppCode>
<SPSelector>2000</SPSelector>
<Currency>USD</Currency>
<AdjustmentType>0</AdjustmentType>
<AdjustmentReason>0</AdjustmentReason>
<Images>
<Image>
<ImageView>Front</ImageView>
<ImageType>CCITTG4</ImageType>
<ImageOffSet>454721</ImageOffSet>
<ImageLength>2196</ImageLength>
</Image>
<Image>
<ImageView>Rear</ImageView>
<ImageType>CCITTG4</ImageType>
<ImageOffSet>252054</ImageOffSet>
<ImageLength>1734</ImageLength>
</Image>
</Images>
<CustomerUserInfo>
<Field1>t5011-0000t1001010001o700</Field1>
<Field2>2006</Field2>
<Field3/>
<Field4/>
</CustomerUserInfo>
</Item>
<Item>
<ISN>790100056 </ISN>
<ImageDocID>12529</ImageDocID>
<Gender>CR</Gender>
<Amount>11190.15</Amount>
<TC>009</TC>
<AN>0120000773</AN>
<Fld4/>
<RT>5300-1000</RT>
<RIC/>
<Aux/>
<ACHCode>Check21</ACHCode>
<ACHConvertedRT/>
<ACHConvertedAccount/>
<IsElectronic>FALSE</IsElectronic>
<IsOnUs>TRUE</IsOnUs>
<IsDeleted>FALSE</IsDeleted>
<IsInsert>FALSE</IsInsert>
<IsCorrected>FALSE</IsCorrected>
<IsReject>FALSE</IsReject>
<RejectReason>0</RejectReason>
<OutsortReason>0</OutsortReason>
<Availability>0</Availability>
<AppCode>0</AppCode>
<SPSelector>1000</SPSelector>
<Currency>USD</Currency>
<AdjustmentType>0</AdjustmentType>
<AdjustmentReason>0</AdjustmentReason>
<Images>
<Image>
<ImageView>Front</ImageView>
<ImageType>CCITTG4</ImageType>
<ImageOffSet>456917</ImageOffSet>
<ImageLength>4335</ImageLength>
</Image>
<Image>
<ImageView>Rear</ImageView>
<ImageType>CCITTG4</ImageType>
<ImageOffSet>253788</ImageOffSet>
<ImageLength>4101</ImageLength>
</Image>
</Images>
<CustomerUserInfo>
<Field1>t5300-1000t009</Field1>
<Field2>1001</Field2>
<Field3/>
<Field4/>
</CustomerUserInfo>
</Item>
<Item>
<ISN>790100057 </ISN>
<ImageDocID>12530</ImageDocID>
<Gender>DR</Gender>
<Amount>11190.15</Amount>
<TC/>
<AN>68001764644391</AN>
<Fld4/>
<RT>102000979</RT>
<RIC/>
<Aux>225127</Aux>
<ACHCode>Check21</ACHCode>
<ACHConvertedRT/>
<ACHConvertedAccount/>
<IsElectronic>FALSE</IsElectronic>
<IsOnUs>FALSE</IsOnUs>
<IsDeleted>FALSE</IsDeleted>
<IsInsert>FALSE</IsInsert>
<IsCorrected>FALSE</IsCorrected>
<IsReject>FALSE</IsReject>
<RejectReason>0</RejectReason>
<OutsortReason>0</OutsortReason>
<Availability>0</Availability>
<AppCode>0</AppCode>
<SPSelector>8000</SPSelector>
<Currency>USD</Currency>
<AdjustmentType>0</AdjustmentType>
<AdjustmentReason>0</AdjustmentReason>
<Images>
<Image>
<ImageView>Front</ImageView>
<ImageType>CCITTG4</ImageType>
<ImageOffSet>461252</ImageOffSet>
<ImageLength>17986</ImageLength>
</Image>
<Image>
<ImageView>Rear</ImageView>
<ImageType>CCITTG4</ImageType>
<ImageOffSet>257889</ImageOffSet>
<ImageLength>8432</ImageLength>
</Image>
</Images>
<CustomerUserInfo>
<Field1>o225127ot102000979t68001764644391o</Field1>
<Field2>8000</Field2>
<Field3/>
<Field4>0011000110000000000000000</Field4>
</CustomerUserInfo>
</Item>
<Item>
<ISN>790100058 </ISN>
<ImageDocID>12531</ImageDocID>
<Gender>DR</Gender>
<Amount>100.00</Amount>
<TC>1436</TC>
<AN>004969395616</AN>
<Fld4/>
<RT>122400724</RT>
<RIC/>
<Aux/>
<ACHCode>Check21</ACHCode>
<ACHConvertedRT/>
<ACHConvertedAccount/>
<IsElectronic>FALSE</IsElectronic>
<IsOnUs>FALSE</IsOnUs>
<IsDeleted>TRUE</IsDeleted>
<IsInsert>FALSE</IsInsert>
<IsCorrected>FALSE</IsCorrected>
<IsReject>FALSE</IsReject>
<RejectReason>0</RejectReason>
<OutsortReason>0</OutsortReason>
<Availability>0</Availability>
<AppCode>0</AppCode>
<SPSelector>8000</SPSelector>
<Currency>USD</Currency>
<AdjustmentType>0</AdjustmentType>
<AdjustmentReason>0</AdjustmentReason>
<Images>
<Image>
<ImageView>Front</ImageView>
<ImageType>CCITTG4</ImageType>
<ImageOffSet>479238</ImageOffSet>
<ImageLength>13393</ImageLength>
</Image>
<Image>
<ImageView>Rear</ImageView>
<ImageType>CCITTG4</ImageType>
<ImageOffSet>266321</ImageOffSet>
<ImageLength>2824</ImageLength>
</Image>
</Images>
<CustomerUserInfo>
<Field1>t122400724t004969395616o1436</Field1>
<Field2>8000</Field2>
<Field3/>
<Field4>0011000110000000000000000</Field4>
</CustomerUserInfo>
</Item>
<Item>
<ISN>790100059 </ISN>
<ImageDocID>12532</ImageDocID>
<Gender>CR</Gender>
<Amount>350000.00</Amount>
<TC>009</TC>
<AN>0100000140</AN>
<Fld4/>
<RT>031919186</RT>
<RIC/>
<Aux>000035</Aux>
<ACHCode>Check21</ACHCode>
<ACHConvertedRT/>
<ACHConvertedAccount/>
<IsElectronic>FALSE</IsElectronic>
<IsOnUs>TRUE</IsOnUs>
<IsDeleted>FALSE</IsDeleted>
<IsInsert>FALSE</IsInsert>
<IsCorrected>FALSE</IsCorrected>
<IsReject>FALSE</IsReject>
<RejectReason>0</RejectReason>
<OutsortReason>0</OutsortReason>
<Availability>0</Availability>
<AppCode>0</AppCode>
<SPSelector>1000</SPSelector>
<Currency>USD</Currency>
<AdjustmentType>0</AdjustmentType>
<AdjustmentReason>0</AdjustmentReason>
<Images>
<Image>
<ImageView>Front</ImageView>
<ImageType>CCITTG4</ImageType>
<ImageOffSet>492631</ImageOffSet>
<ImageLength>5447</ImageLength>
</Image>
<Image>
<ImageView>Rear</ImageView>
<ImageType>CCITTG4</ImageType>
<ImageOffSet>269145</ImageOffSet>
<ImageLength>3026</ImageLength>
</Image>
</Images>
<CustomerUserInfo>
<Field1>o000035ot031919186t0100000140o009</Field1>
<Field2>1001</Field2>
<Field3/>
<Field4>0011000110000000000000000</Field4>
</CustomerUserInfo>
</Item>
<Item>
<ISN>790100060 </ISN>
<ImageDocID>12533</ImageDocID>
<Gender>DR</Gender>
<Amount>350000.00</Amount>
<TC>500</TC>
<AN>1390050098</AN>
<Fld4/>
<RT>5021-1000</RT>
<RIC/>
<Aux/>
<ACHCode>Check21</ACHCode>
<ACHConvertedRT/>
<ACHConvertedAccount/>
<IsElectronic>FALSE</IsElectronic>
<IsOnUs>TRUE</IsOnUs>
<IsDeleted>FALSE</IsDeleted>
<IsInsert>FALSE</IsInsert>
<IsCorrected>FALSE</IsCorrected>
<IsReject>FALSE</IsReject>
<RejectReason>0</RejectReason>
<OutsortReason>0</OutsortReason>
<Availability>0</Availability>
<AppCode>0</AppCode>
<SPSelector>2000</SPSelector>
<Currency>USD</Currency>
<AdjustmentType>0</AdjustmentType>
<AdjustmentReason>0</AdjustmentReason>
<Images>
<Image>
<ImageView>Front</ImageView>
<ImageType>CCITTG4</ImageType>
<ImageOffSet>498078</ImageOffSet>
<ImageLength>6115</ImageLength>
</Image>
<Image>
<ImageView>Rear</ImageView>
<ImageType>CCITTG4</ImageType>
<ImageOffSet>272171</ImageOffSet>
<ImageLength>1578</ImageLength>
</Image>
</Images>
<CustomerUserInfo>
<Field1>t5021-1000t500</Field1>
<Field2>2006</Field2>
<Field3/>
<Field4/>
</CustomerUserInfo>
</Item>
<Item>
<ISN>790100061 </ISN>
<ImageDocID>12534</ImageDocID>
<Gender>CR</Gender>
<Amount>1750.00</Amount>
<TC>400</TC>
<AN>1770010098</AN>
<Fld4/>
<RT>5020-1000</RT>
<RIC/>
<Aux/>
<ACHCode>Check21</ACHCode>
<ACHConvertedRT/>
<ACHConvertedAccount/>
<IsElectronic>FALSE</IsElectronic>
<IsOnUs>TRUE</IsOnUs>
<IsDeleted>FALSE</IsDeleted>
<IsInsert>FALSE</IsInsert>
<IsCorrected>FALSE</IsCorrected>
<IsReject>FALSE</IsReject>
<RejectReason>0</RejectReason>
<OutsortReason>0</OutsortReason>
<Availability>0</Availability>
<AppCode>0</AppCode>
<SPSelector>1000</SPSelector>
<Currency>USD</Currency>
<AdjustmentType>0</AdjustmentType>
<AdjustmentReason>0</AdjustmentReason>
<Images>
<Image>
<ImageView>Front</ImageView>
<ImageType>CCITTG4</ImageType>
<ImageOffSet>504193</ImageOffSet>
<ImageLength>5650</ImageLength>
</Image>
<Image>
<ImageView>Rear</ImageView>
<ImageType>CCITTG4</ImageType>
<ImageOffSet>273749</ImageOffSet>
<ImageLength>2963</ImageLength>
</Image>
</Images>
<CustomerUserInfo>
<Field1>t5020-1000t400</Field1>
<Field2>1006</Field2>
<Field3/>
<Field4/>
</CustomerUserInfo>
</Item>
<Item>
<ISN>790100062 </ISN>
<ImageDocID>12535</ImageDocID>
<Gender>DR</Gender>
<Amount>1750.00</Amount>
<TC/>
<AN>2000012542651</AN>
<Fld4/>
<RT>031000503</RT>
<RIC/>
<Aux>017371</Aux>
<ACHCode>Check21</ACHCode>
<ACHConvertedRT/>
<ACHConvertedAccount/>
<IsElectronic>FALSE</IsElectronic>
<IsOnUs>FALSE</IsOnUs>
<IsDeleted>FALSE</IsDeleted>
<IsInsert>FALSE</IsInsert>
<IsCorrected>FALSE</IsCorrected>
<IsReject>FALSE</IsReject>
<RejectReason>0</RejectReason>
<OutsortReason>0</OutsortReason>
<Availability>0</Availability>
<AppCode>0</AppCode>
<SPSelector>8000</SPSelector>
<Currency>USD</Currency>
<AdjustmentType>0</AdjustmentType>
<AdjustmentReason>0</AdjustmentReason>
<Images>
<Image>
<ImageView>Front</ImageView>
<ImageType>CCITTG4</ImageType>
<ImageOffSet>509843</ImageOffSet>
<ImageLength>10988</ImageLength>
</Image>
<Image>
<ImageView>Rear</ImageView>
<ImageType>CCITTG4</ImageType>
<ImageOffSet>276712</ImageOffSet>
<ImageLength>2374</ImageLength>
</Image>
</Images>
<CustomerUserInfo>
<Field1>o017371ot031000503t2000012542651o</Field1>
<Field2>8000</Field2>
<Field3/>
<Field4>0011000110000000000000000</Field4>
</CustomerUserInfo>
</Item>
<Item>
<ISN>790100063 </ISN>
<ImageDocID>12536</ImageDocID>
<Gender>CR</Gender>
<Amount>60.00</Amount>
<TC>600</TC>
<AN>1001010001</AN>
<Fld4/>
<RT>5010-0000</RT>
<RIC/>
<Aux/>
<ACHCode>Check21</ACHCode>
<ACHConvertedRT/>
<ACHConvertedAccount/>
<IsElectronic>FALSE</IsElectronic>
<IsOnUs>TRUE</IsOnUs>
<IsDeleted>FALSE</IsDeleted>
<IsInsert>FALSE</IsInsert>
<IsCorrected>FALSE</IsCorrected>
<IsReject>FALSE</IsReject>
<RejectReason>0</RejectReason>
<OutsortReason>0</OutsortReason>
<Availability>0</Availability>
<AppCode>0</AppCode>
<SPSelector>1000</SPSelector>
<Currency>USD</Currency>
<AdjustmentType>0</AdjustmentType>
<AdjustmentReason>0</AdjustmentReason>
<Images>
<Image>
<ImageView>Front</ImageView>
<ImageType>CCITTG4</ImageType>
<ImageOffSet>520831</ImageOffSet>
<ImageLength>2654</ImageLength>
</Image>
<Image>
<ImageView>Rear</ImageView>
<ImageType>CCITTG4</ImageType>
<ImageOffSet>279086</ImageOffSet>
<ImageLength>2314</ImageLength>
</Image>
</Images>
<CustomerUserInfo>
<Field1>t5010-0000t1001010001o600</Field1>
<Field2>1006</Field2>
<Field3/>
<Field4/>
</CustomerUserInfo>
</Item>
<Item>
<ISN>790100064 </ISN>
<ImageDocID>12537</ImageDocID>
<Gender>DR</Gender>
<Amount>60.00</Amount>
<TC>046</TC>
<AN>0120000104</AN>
<Fld4/>
<RT>5301-1000</RT>
<RIC/>
<Aux/>
<ACHCode>Check21</ACHCode>
<ACHConvertedRT/>
<ACHConvertedAccount/>
<IsElectronic>FALSE</IsElectronic>
<IsOnUs>TRUE</IsOnUs>
<IsDeleted>FALSE</IsDeleted>
<IsInsert>FALSE</IsInsert>
<IsCorrected>FALSE</IsCorrected>
<IsReject>FALSE</IsReject>
<RejectReason>0</RejectReason>
<OutsortReason>0</OutsortReason>
<Availability>0</Availability>
<AppCode>0</AppCode>
<SPSelector>2000</SPSelector>
<Currency>USD</Currency>
<AdjustmentType>0</AdjustmentType>
<AdjustmentReason>0</AdjustmentReason>
<Images>
<Image>
<ImageView>Front</ImageView>
<ImageType>CCITTG4</ImageType>
<ImageOffSet>523485</ImageOffSet>
<ImageLength>3894</ImageLength>
</Image>
<Image>
<ImageView>Rear</ImageView>
<ImageType>CCITTG4</ImageType>
<ImageOffSet>281400</ImageOffSet>
<ImageLength>2795</ImageLength>
</Image>
</Images>
<CustomerUserInfo>
<Field1>t5301-1000t046</Field1>
<Field2>2001</Field2>
<Field3/>
<Field4/>
</CustomerUserInfo>
</Item>
</Items>
</Batch>
</Batches>
<BatchCount>1</BatchCount>
</Block>
</Blocks>
<BlockCount>1</BlockCount>
</Job>
</Jobs>
</FileExchange>

Jun 27 '08 #2
If you want a simple solution, then I would just use the XmlTextReader class
to do what you want. You can give this code a try. This just adds up all of
the batch ticket amounts. Here it is:

using System.Xml;

XmlTextReader reader = new XmlTextReader("FileExchange.xml");
float batchTicketAmount = 0.0f;
bool batchTicketAmountStartElement = false;

while (reader.Read())
{
switch (reader.NodeType)
{
case XmlNodeType.Element: // The node is an element.
if (reader.Name == "BatchTktAmount")
{
batchTicketAmountStartElement = true;
}
break;
case XmlNodeType.Text: //Display the text in each element.
if (batchTicketAmountStartElement)
{
try
{
batchTicketAmount += float.Parse(reader.Value);
}
catch (Exception ex)
{
System.Console.WriteLine(ex.Message);
}
}
break;
case XmlNodeType.EndElement: //Display the end of the element.
if (reader.Name == "BatchTktAmount")
batchTicketAmountStartElement = false;
break;
}
}

Console.WriteLine(batchTicketAmount);
"DavidM" wrote:
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 file, then spit out totals.

Since I haven't worked with XML too much in C#, I'm trying to develop a
structured and easy-to-read way to parse the file.

Essentially, I would like to read the file and add the "BatchTktAmountfor
any <Batchelements that may exist. There could be 1 or more...

As a verification, I may also want to add the <BATCH\Itemselements, there
could be 1 or more, and if <Genderis a credit "CR", accumulate totals for
credit items. If <Genderis a debit "DR", acculate totals for debit items.

Total items should equal the total batches.

I guess if I had relatively good XML parsing code, I could figure out how to
read the file in such a way to get the information. The real kicker for me
is the multiple batches and items.

Sample is below.

Any help would be appreciated

<FileExchange>
<Version>
<MajorVer>1</MajorVer>
<MinorVer>0</MinorVer>
</Version>
<Jobs>
<Job>
<StartTime>20080610:171706</StartTime>
<EndTime>20080610:171747</EndTime>
<BusinessDate>20080610</BusinessDate>
<Device>26</Device>
<Site/>
<ProcType>Prime</ProcType>
<WorkTypeNumber>1</WorkTypeNumber>
<ClearingType>OutClearing</ClearingType>
<DebitsFirst>FALSE</DebitsFirst>
<SortFamily>900</SortFamily>
<Imaged>TRUE</Imaged>
<NbrOfBlocksInJob>1</NbrOfBlocksInJob>
<CycleID>A</CycleID>
<Blocks>
<Block>
<BlkNbr>64</BlkNbr>
<BlkStartTime>20080610:171706</BlkStartTime>
<BlkEndTime>20080610:171747</BlkEndTime>
<BlkSeqInJob>1</BlkSeqInJob>
<BlkFrontImgFileName>\\VMSERVER1\MyApp\AllItemsExt ract\G179BC\0064_5.fim</BlkFrontImgFileName>
<BlkRearImgFileName>\\VMSERVER1\MyApp\AllItemsExtr act\G179BC\0064_5.rim</BlkRearImgFileName>
<Batches>
<Batch>
<BatchNbr>1</BatchNbr>
<BranchData>
<BranchID>079010</BranchID>
<BranchDeviceID>79010</BranchDeviceID>
<BranchTill>0</BranchTill>
<BranchBatchNbr>1</BranchBatchNbr>
<BranchBusinessDate>20080610</BranchBusinessDate>
</BranchData>
<BatchTktAmount>617181.39</BatchTktAmount>
<BatchTktTC/>
<BatchTktAN/>
<BatchTktRT>444444442</BatchTktRT>
<BatchTktAux/>
<Items>
<Item>
<ISN>790100003 </ISN>
<ImageDocID>12478</ImageDocID>
<Gender>CR</Gender>
<Amount>17000.00</Amount>
<TC>009</TC>
<AN>0120000153</AN>
<Fld4/>
<RT>5300-1000</RT>
<RIC/>
<Aux/>
<ACHCode>Check21</ACHCode>
<ACHConvertedRT/>
<ACHConvertedAccount/>
<IsElectronic>FALSE</IsElectronic>
<IsOnUs>TRUE</IsOnUs>
<IsDeleted>FALSE</IsDeleted>
<IsInsert>FALSE</IsInsert>
<IsCorrected>FALSE</IsCorrected>
<IsReject>FALSE</IsReject>
<RejectReason>0</RejectReason>
<OutsortReason>0</OutsortReason>
<Availability>0</Availability>
<AppCode>0</AppCode>
<SPSelector>1000</SPSelector>
<Currency>USD</Currency>
<AdjustmentType>0</AdjustmentType>
<AdjustmentReason>0</AdjustmentReason>
<Images>
<Image>
<ImageView>Front</ImageView>
<ImageType>CCITTG4</ImageType>
<ImageOffSet>514</ImageOffSet>
<ImageLength>6298</ImageLength>
</Image>
<Image>
<ImageView>Rear</ImageView>
<ImageType>CCITTG4</ImageType>
<ImageOffSet>514</ImageOffSet>
<ImageLength>5240</ImageLength>
</Image>
</Images>
<CustomerUserInfo>
<Field1>t5300-1000t0120000153o009</Field1>
<Field2>1001</Field2>
<Field3/>
<Field4/>
</CustomerUserInfo>
</Item>
<Item>
<ISN>790100004 </ISN>
<ImageDocID>12479</ImageDocID>
<Gender>DR</Gender>
<Amount>17000.00</Amount>
<TC>1011</TC>
<AN>362343062</AN>
<Fld4/>
<RT>999999999</RT>
<RIC/>
<Aux/>
<ACHCode>Check21</ACHCode>
<ACHConvertedRT/>
<ACHConvertedAccount/>
<IsElectronic>FALSE</IsElectronic>
<IsOnUs>FALSE</IsOnUs>
<IsDeleted>FALSE</IsDeleted>
<IsInsert>FALSE</IsInsert>
<IsCorrected>FALSE</IsCorrected>
<IsReject>FALSE</IsReject>
<RejectReason>0</RejectReason>
<OutsortReason>0</OutsortReason>
<Availability>0</Availability>
<AppCode>0</AppCode>
<SPSelector>8000</SPSelector>
<Currency>USD</Currency>
<AdjustmentType>0</AdjustmentType>
<AdjustmentReason>0</AdjustmentReason>
<Images>
<Image>
<ImageView>Front</ImageView>
<ImageType>CCITTG4</ImageType>
<ImageOffSet>6812</ImageOffSet>
<ImageLength>7624</ImageLength>
</Image>
<Image>
<ImageView>Rear</ImageView>
<ImageType>CCITTG4</ImageType>
<ImageOffSet>5754</ImageOffSet>
<ImageLength>2820</ImageLength>
</Image>
</Images>
<CustomerUserInfo>
<Field1>t031301422t362343062o1011</Field1>
<Field2>8000</Field2>
<Field3/>
<Field4>0011000110000000000000000</Field4>
</CustomerUserInfo>
</Item>
<Item>
<ISN>790100005 </ISN>
<ImageDocID>12480</ImageDocID>
<Gender>CR</Gender>
<Amount>12405.18</Amount>
<TC>109</TC>
<AN>014002437</AN>
<Fld4/>
<RT>5009-1000</RT>
<RIC/>
<Aux/>
<ACHCode>Check21</ACHCode>
<ACHConvertedRT/>
<ACHConvertedAccount/>
<IsElectronic>FALSE</IsElectronic>
<IsOnUs>TRUE</IsOnUs>
<IsDeleted>FALSE</IsDeleted>
<IsInsert>FALSE</IsInsert>
<IsCorrected>FALSE</IsCorrected>
<IsReject>FALSE</IsReject>
<RejectReason>0</RejectReason>
<OutsortReason>0</OutsortReason>
<Availability>0</Availability>
<AppCode>0</AppCode>
<SPSelector>1000</SPSelector>
<Currency>USD</Currency>
<AdjustmentType>0</AdjustmentType>
<AdjustmentReason>0</AdjustmentReason>
<Images>
<Image>
<ImageView>Front</ImageView>
<ImageType>CCITTG4</ImageType>
<ImageOffSet>14436</ImageOffSet>
<ImageLength>4934</ImageLength>
</Image>
<Image>
<ImageView>Rear</ImageView>
<ImageType>CCITTG4</ImageType>
<ImageOffSet>8574</ImageOffSet>
<ImageLength>4145</ImageLength>
</Image>
</Images>
<CustomerUserInfo>
<Field1>t5009-1000t109</Field1>
<Field2>1003</Field2>
<Field3/>
<Field4/>
</CustomerUserInfo>
</Item>
<Item>
<ISN>790100006 </ISN>
<ImageDocID>12481</ImageDocID>
<Gender>DR</Gender>
<Amount>1733.06</Amount>
<TC/>
<AN>1002419133</AN>
<Fld4/>
<RT>043301627</RT>
<RIC/>
<Aux>0013866851</Aux>
<ACHCode>Check21</ACHCode>
<ACHConvertedRT/>
<ACHConvertedAccount/>
<IsElectronic>FALSE</IsElectronic>
<IsOnUs>FALSE</IsOnUs>
<IsDeleted>FALSE</IsDeleted>
<IsInsert>FALSE</IsInsert>
<IsCorrected>FALSE</IsCorrected>
<IsReject>FALSE</IsReject>
<RejectReason>0</RejectReason>
<OutsortReason>0</OutsortReason>
<Availability>0</Availability>
<AppCode>0</AppCode>
<SPSelector>8000</SPSelector>
<Currency>USD</Currency>
<AdjustmentType>0</AdjustmentType>
<AdjustmentReason>0</AdjustmentReason>
<Images>
<Image>
<ImageView>Front</ImageView>
<ImageType>CCITTG4</ImageType>
<ImageOffSet>19370</ImageOffSet>
<ImageLength>10443</ImageLength>
</Image>
<Image>
<ImageView>Rear</ImageView>
<ImageType>CCITTG4</ImageType>
<ImageOffSet>12719</ImageOffSet>
<ImageLength>5143</ImageLength>
</Image>
</Images>
<CustomerUserInfo>
<Field1>o0013866851ot043301627t1002419133o</Field1>
<Field2>8000</Field2>
<Field3/>
<Field4>0011000110000000000000000</Field4>
</CustomerUserInfo>
</Item>
<Item>
<ISN>790100007 </ISN>
<ImageDocID>12482</ImageDocID>
<Gender>DR</Gender>
<Amount>10672.12</Amount>
<TC/>
<AN>009000091</AN>
<Fld4/>
<RT>999999999</RT>
<RIC/>
<Aux>1095468</Aux>
<ACHCode>Check21</ACHCode>
<ACHConvertedRT/>
<ACHConvertedAccount/>
<IsElectronic>FALSE</IsElectronic>
<IsOnUs>FALSE</IsOnUs>
<IsDeleted>FALSE</IsDeleted>
<IsInsert>FALSE</IsInsert>
<IsCorrected>FALSE</IsCorrected>
<IsReject>FALSE</IsReject>
<RejectReason>0</RejectReason>
<OutsortReason>0</OutsortReason>
<Availability>0</Availability>
<AppCode>0</AppCode>
<SPSelector>8000</SPSelector>
<Currency>USD</Currency>
<AdjustmentType>0</AdjustmentType>
<AdjustmentReason>0</AdjustmentReason>
<Images>
<Image>
<ImageView>Front</ImageView>
<ImageType>CCITTG4</ImageType>
<ImageOffSet>29813</ImageOffSet>
<ImageLength>22934</ImageLength>
</Image>
<Image>
<ImageView>Rear</ImageView>
<ImageType>CCITTG4</ImageType>
Jun 27 '08 #3
John -- thanks for your reply. I'm reading it now and like the DDJ article.

"John Timney (MVP)" wrote:
If you can convert it into a dataset, then you can easily bind to it and do
usual DB type stuff with its values

http://devpinoy.org/blogs/keithrull/...o-dataset.aspx

http://www.ddj.com/windows/184416669
Regards

John Timney (MVP)
http://www.johntimney.com
http://www.johntimney.com/blog

"DavidM" <Da****@discussions.microsoft.comwrote in message
news:6B**********************************@microsof t.com...
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 file, then spit out
totals.

Since I haven't worked with XML too much in C#, I'm trying to develop a
structured and easy-to-read way to parse the file.

Essentially, I would like to read the file and add the "BatchTktAmount>
for
any <Batchelements that may exist. There could be 1 or more...

As a verification, I may also want to add the <BATCH\Itemselements,
there
could be 1 or more, and if <Genderis a credit "CR", accumulate totals
for
credit items. If <Genderis a debit "DR", acculate totals for debit
items.

Total items should equal the total batches.

I guess if I had relatively good XML parsing code, I could figure out how
to
read the file in such a way to get the information. The real kicker for
me
is the multiple batches and items.

Sample is below.

Any help would be appreciated

<FileExchange>
<Version>
<MajorVer>1</MajorVer>
<MinorVer>0</MinorVer>
</Version>
<Jobs>
<Job>
<StartTime>20080610:171706</StartTime>
<EndTime>20080610:171747</EndTime>
<BusinessDate>20080610</BusinessDate>
<Device>26</Device>
<Site/>
<ProcType>Prime</ProcType>
<WorkTypeNumber>1</WorkTypeNumber>
<ClearingType>OutClearing</ClearingType>
<DebitsFirst>FALSE</DebitsFirst>
<SortFamily>900</SortFamily>
<Imaged>TRUE</Imaged>
<NbrOfBlocksInJob>1</NbrOfBlocksInJob>
<CycleID>A</CycleID>
<Blocks>
<Block>
<BlkNbr>64</BlkNbr>
<BlkStartTime>20080610:171706</BlkStartTime>
<BlkEndTime>20080610:171747</BlkEndTime>
<BlkSeqInJob>1</BlkSeqInJob>
<BlkFrontImgFileName>\\VMSERVER1\MyApp\AllItemsExt ract\G179BC\0064_5.fim</BlkFrontImgFileName>
<BlkRearImgFileName>\\VMSERVER1\MyApp\AllItemsExtr act\G179BC\0064_5.rim</BlkRearImgFileName>
<Batches>
<Batch>
<BatchNbr>1</BatchNbr>
<BranchData>
<BranchID>079010</BranchID>
<BranchDeviceID>79010</BranchDeviceID>
<BranchTill>0</BranchTill>
<BranchBatchNbr>1</BranchBatchNbr>
<BranchBusinessDate>20080610</BranchBusinessDate>
</BranchData>
<BatchTktAmount>617181.39</BatchTktAmount>
<BatchTktTC/>
<BatchTktAN/>
<BatchTktRT>444444442</BatchTktRT>
<BatchTktAux/>
<Items>
<Item>
<ISN>790100003 </ISN>
<ImageDocID>12478</ImageDocID>
<Gender>CR</Gender>
<Amount>17000.00</Amount>
<TC>009</TC>
<AN>0120000153</AN>
<Fld4/>
<RT>5300-1000</RT>
<RIC/>
<Aux/>
<ACHCode>Check21</ACHCode>
<ACHConvertedRT/>
<ACHConvertedAccount/>
<IsElectronic>FALSE</IsElectronic>
<IsOnUs>TRUE</IsOnUs>
<IsDeleted>FALSE</IsDeleted>
<IsInsert>FALSE</IsInsert>
<IsCorrected>FALSE</IsCorrected>
<IsReject>FALSE</IsReject>
<RejectReason>0</RejectReason>
<OutsortReason>0</OutsortReason>
<Availability>0</Availability>
<AppCode>0</AppCode>
<SPSelector>1000</SPSelector>
<Currency>USD</Currency>
<AdjustmentType>0</AdjustmentType>
<AdjustmentReason>0</AdjustmentReason>
<Images>
<Image>
<ImageView>Front</ImageView>
<ImageType>CCITTG4</ImageType>
<ImageOffSet>514</ImageOffSet>
<ImageLength>6298</ImageLength>
</Image>
<Image>
<ImageView>Rear</ImageView>
<ImageType>CCITTG4</ImageType>
<ImageOffSet>514</ImageOffSet>
<ImageLength>5240</ImageLength>
</Image>
</Images>
<CustomerUserInfo>
<Field1>t5300-1000t0120000153o009</Field1>
<Field2>1001</Field2>
<Field3/>
<Field4/>
</CustomerUserInfo>
</Item>
<Item>
<ISN>790100004 </ISN>
<ImageDocID>12479</ImageDocID>
<Gender>DR</Gender>
<Amount>17000.00</Amount>
<TC>1011</TC>
<AN>362343062</AN>
<Fld4/>
<RT>999999999</RT>
<RIC/>
<Aux/>
<ACHCode>Check21</ACHCode>
<ACHConvertedRT/>
<ACHConvertedAccount/>
<IsElectronic>FALSE</IsElectronic>
<IsOnUs>FALSE</IsOnUs>
<IsDeleted>FALSE</IsDeleted>
<IsInsert>FALSE</IsInsert>
<IsCorrected>FALSE</IsCorrected>
<IsReject>FALSE</IsReject>
<RejectReason>0</RejectReason>
<OutsortReason>0</OutsortReason>
<Availability>0</Availability>
<AppCode>0</AppCode>
<SPSelector>8000</SPSelector>
<Currency>USD</Currency>
<AdjustmentType>0</AdjustmentType>
<AdjustmentReason>0</AdjustmentReason>
<Images>
<Image>
<ImageView>Front</ImageView>
<ImageType>CCITTG4</ImageType>
<ImageOffSet>6812</ImageOffSet>
<ImageLength>7624</ImageLength>
</Image>
<Image>
<ImageView>Rear</ImageView>
<ImageType>CCITTG4</ImageType>
<ImageOffSet>5754</ImageOffSet>
<ImageLength>2820</ImageLength>
</Image>
</Images>
<CustomerUserInfo>
<Field1>t031301422t362343062o1011</Field1>
<Field2>8000</Field2>
<Field3/>
<Field4>0011000110000000000000000</Field4>
</CustomerUserInfo>
</Item>
<Item>
<ISN>790100005 </ISN>
<ImageDocID>12480</ImageDocID>
<Gender>CR</Gender>
<Amount>12405.18</Amount>
<TC>109</TC>
<AN>014002437</AN>
<Fld4/>
<RT>5009-1000</RT>
<RIC/>
<Aux/>
<ACHCode>Check21</ACHCode>
<ACHConvertedRT/>
<ACHConvertedAccount/>
<IsElectronic>FALSE</IsElectronic>
<IsOnUs>TRUE</IsOnUs>
<IsDeleted>FALSE</IsDeleted>
<IsInsert>FALSE</IsInsert>
<IsCorrected>FALSE</IsCorrected>
<IsReject>FALSE</IsReject>
<RejectReason>0</RejectReason>
<OutsortReason>0</OutsortReason>
<Availability>0</Availability>
<AppCode>0</AppCode>
<SPSelector>1000</SPSelector>
<Currency>USD</Currency>
<AdjustmentType>0</AdjustmentType>
<AdjustmentReason>0</AdjustmentReason>
<Images>
<Image>
<ImageView>Front</ImageView>
<ImageType>CCITTG4</ImageType>
<ImageOffSet>14436</ImageOffSet>
<ImageLength>4934</ImageLength>
</Image>
<Image>
<ImageView>Rear</ImageView>
<ImageType>CCITTG4</ImageType>
<ImageOffSet>8574</ImageOffSet>
<ImageLength>4145</ImageLength>
</Image>
</Images>
<CustomerUserInfo>
<Field1>t5009-1000t109</Field1>
<Field2>1003</Field2>
<Field3/>
<Field4/>
</CustomerUserInfo>
</Item>
<Item>
<ISN>790100006 </ISN>
<ImageDocID>12481</ImageDocID>
<Gender>DR</Gender>
<Amount>1733.06</Amount>
<TC/>
<AN>1002419133</AN>
<Fld4/>
<RT>043301627</RT>
<RIC/>
<Aux>0013866851</Aux>
<ACHCode>Check21</ACHCode>
<ACHConvertedRT/>
<ACHConvertedAccount/>
<IsElectronic>FALSE</IsElectronic>
<IsOnUs>FALSE</IsOnUs>
<IsDeleted>FALSE</IsDeleted>
<IsInsert>FALSE</IsInsert>
<IsCorrected>FALSE</IsCorrected>
<IsReject>FALSE</IsReject>
<RejectReason>0</RejectReason>
<OutsortReason>0</OutsortReason>
<Availability>0</Availability>
<AppCode>0</AppCode>
<SPSelector>8000</SPSelector>
<Currency>USD</Currency>
<AdjustmentType>0</AdjustmentType>
<AdjustmentReason>0</AdjustmentReason>
<Images>
<Image>
<ImageView>Front</ImageView>
<ImageType>CCITTG4</ImageType>
<ImageOffSet>19370</ImageOffSet>
<ImageLength>10443</ImageLength>
</Image>
<Image>
<ImageView>Rear</ImageView>
<ImageType>CCITTG4</ImageType>
<ImageOffSet>12719</ImageOffSet>
<ImageLength>5143</ImageLength>
</Image>
</Images>
<CustomerUserInfo>
<Field1>o0013866851ot043301627t1002419133o</Field1>
<Field2>8000</Field2>
<Field3/>
<Field4>0011000110000000000000000</Field4>
</CustomerUserInfo>
</Item>
<Item>
<ISN>790100007 </ISN>
<ImageDocID>12482</ImageDocID>
<Gender>DR</Gender>
<Amount>10672.12</Amount>
<TC/>
<AN>009000091</AN>
<Fld4/>
<RT>999999999</RT>
<RIC/>
<Aux>1095468</Aux>
Jun 27 '08 #4
You're welcome. Accumulating the items should be easy. You just do
everything in the same while() loop. Just look at how I looked for the
BatchTktAmount Element. You would just take that same approach to look for
the Item Element. That is, set a boolean so that you know that tag has
started. Then, check your boolean to see if you are in an Item Element. If
you are, then set another boolean once you are in a Gender Element. If the
XmlNodeType is Text, then check if you are in a Gender Element by checking
your boolean. If the Gender text matches "DR", then set another boolean that
you are in a DR Gender Element... otherwise set your DR Gender Element
boolean to false.

Now, if you are in an Item Element, check if you are in an Amount element.
If you are, then set another boolean. If the XmlNodeType is Text, then check
if you are in an Amount Element by checking your boolean. If you are, then
check your boolean for DR Gender Element. If true, then add to your Credit
total, otherwise add to your Debit total.

That's it.

For my previous example, you can do the same thing with LINQ for XML in .NET
3.5 with the following code:
using System.Xml;
using System.Xml.Linq;

double batchTicketAmount = 0.0d;

XDocument loaded = XDocument.Load("FileExchange.xml");
var q = (from b in loaded.Descendants("Batch")
select (double)b.Element("BatchTktAmount")).Sum(rec =rec);
batchTicketAmount = (double)q;
Once again, it would be trivial to add up all the Item Elements as well, but
you would need to know a bit of LINQ to do so.
Jun 27 '08 #5
Hi David,

Tim provided some suggestion about using XmlTextReader, that is quite good
for memory restricted condition since it avoid loading the envire XML
document into memory. If memory is not the problem, and you have ample
memory to hold the entire XMLdocument, you can consider load the file into
XmlDocument and than perform XPath query to get all the expected
elements/nodes. Here are some good articles introducing execute Xpath query
via .NET xml document or xpath navigator classes:

#.NET and XML: XPath Queries
http://www.developer.com/xml/article.php/3383961

#Easily navigate XML with VB.NET and XPath
http://articles.techrepublic.com.com...1-5035074.html

#INFO: Roadmap for Executing XPath Queries in .NET Applications
http://support.microsoft.com/kb/313828

for your sample xml file here, I've written a simple console app to
demonstrate how to query all the batch elements(and its inner tktamount and
all the items ...)
>>>>>>>>>>>>>>>>>>>>>>>>>
class Program
{
static void Main(string[] args)
{
Run_DOM();
}
static void Run_DOM()
{
XmlDocument doc = new XmlDocument();
doc.Load(@"..\..\data.xml");
//query all batches...
XmlNodeList batches = doc.SelectNodes("//Batches/Batch");

if(batches!= null)
foreach (XmlNode batch in batches)
{
//for each batch, get Nbr and TktAmount
XmlNode Nbr = batch.SelectSingleNode("./BatchNbr");
XmlNode Amount =
batch.SelectSingleNode("./BatchTktAmount");

Console.WriteLine("######BatchNbr:{0},
BatchTktAmount:{1}#######",
Nbr.InnerText, Amount.InnerText);

//query items of the batch
Console.WriteLine("\tItems:");
XmlNodeList items = batch.SelectNodes("./Items/Item");

foreach (XmlNode item in items)
{
XmlNode isn = item.SelectSingleNode("./ISN");
XmlNode amt = item.SelectSingleNode("./Amount");

Console.WriteLine("\t\tISN:{0}, Amount:{1}"
, isn.InnerText, amt.InnerText);

}

}

}
}
<<<<<<<<<<<<<<<<<<<<<<<<<<

Also, I saw that in Tim's new reply, he mentioned the X-LINQ
feature(provided in .NET 3.5). That is a new XML DOM based processing API
which can do the same thing as the above DOM code(but with different api
and syntax), if you have interests, you can also have a look at LINQ/LINQ
TO XML over MSDN:

#NET Language-Integrated Query for XML Data
http://msdn.microsoft.com/en-us/library/bb308960.aspx

Hope this also helps.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsoft.com.

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.



--------------------
>From: =?Utf-8?B?RGF2aWRN?= <Da****@discussions.microsoft.com>
References: <6B**********************************@microsoft.co m>
<GZ******************************@eclipse.net.uk >
>Subject: Re: How to Parse XML File
Date: Mon, 16 Jun 2008 12:19:02 -0700
>
John -- thanks for your reply. I'm reading it now and like the DDJ
article.
>
"John Timney (MVP)" wrote:
>If you can convert it into a dataset, then you can easily bind to it and
do
>usual DB type stuff with its values

http://devpinoy.org/blogs/keithrull/...onvert-an-xml-
string-to-dataset.aspx
>>
http://www.ddj.com/windows/184416669
Regards

John Timney (MVP)
http://www.johntimney.com
http://www.johntimney.com/blog

"DavidM" <Da****@discussions.microsoft.comwrote in message
news:6B**********************************@microso ft.com...
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 file, then spit out
totals.

Since I haven't worked with XML too much in C#, I'm trying to develop a
structured and easy-to-read way to parse the file.

Essentially, I would like to read the file and add the
"BatchTktAmount>
for
any <Batchelements that may exist. There could be 1 or more...

As a verification, I may also want to add the <BATCH\Itemselements,
there
could be 1 or more, and if <Genderis a credit "CR", accumulate
totals
for
credit items. If <Genderis a debit "DR", acculate totals for debit
items.

Total items should equal the total batches.

I guess if I had relatively good XML parsing code, I could figure out
how

Jun 27 '08 #6
Hi David,

How are you doing? Have you got any progress on this or does the suggestion
in previous messages help you?

If there is anything else need help, welcome to post here.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsoft.com.

==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.


--------------------
>From: st*****@online.microsoft.com (Steven Cheng [MSFT])
Organization: Microsoft
Date: Tue, 17 Jun 2008 02:24:30 GMT
Subject: Re: How to Parse XML File
>
Hi David,

Tim provided some suggestion about using XmlTextReader, that is quite good
for memory restricted condition since it avoid loading the envire XML
document into memory. If memory is not the problem, and you have ample
memory to hold the entire XMLdocument, you can consider load the file into
XmlDocument and than perform XPath query to get all the expected
elements/nodes. Here are some good articles introducing execute Xpath
query
>via .NET xml document or xpath navigator classes:

#.NET and XML: XPath Queries
http://www.developer.com/xml/article.php/3383961

#Easily navigate XML with VB.NET and XPath
http://articles.techrepublic.com.com...1-5035074.html

#INFO: Roadmap for Executing XPath Queries in .NET Applications
http://support.microsoft.com/kb/313828

for your sample xml file here, I've written a simple console app to
demonstrate how to query all the batch elements(and its inner tktamount
and
>all the items ...)
>>>>>>>>>>>>>>>>>>>>>>>>>>
class Program
{
static void Main(string[] args)
{
Run_DOM();
}
static void Run_DOM()
{
XmlDocument doc = new XmlDocument();
doc.Load(@"..\..\data.xml");
//query all batches...
XmlNodeList batches = doc.SelectNodes("//Batches/Batch");

if(batches!= null)
foreach (XmlNode batch in batches)
{
//for each batch, get Nbr and TktAmount
XmlNode Nbr = batch.SelectSingleNode("./BatchNbr");
XmlNode Amount =
batch.SelectSingleNode("./BatchTktAmount");

Console.WriteLine("######BatchNbr:{0},
BatchTktAmount:{1}#######",
Nbr.InnerText, Amount.InnerText);

//query items of the batch
Console.WriteLine("\tItems:");
XmlNodeList items = batch.SelectNodes("./Items/Item");

foreach (XmlNode item in items)
{
XmlNode isn = item.SelectSingleNode("./ISN");
XmlNode amt = item.SelectSingleNode("./Amount");

Console.WriteLine("\t\tISN:{0}, Amount:{1}"
, isn.InnerText, amt.InnerText);

}

}

=
>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 file, then spit out
totals.

Since I haven't worked with XML too much in C#, I'm trying to develop
a
>structured and easy-to-read way to parse the file.

Essentially, I would like to read the file and add the
"BatchTktAmount>
>for
any <Batchelements that may exist. There could be 1 or more...

As a verification, I may also want to add the <BATCH\Itemselements,
there
could be 1 or more, and if <Genderis a credit "CR", accumulate
totals
>for
credit items. If <Genderis a debit "DR", acculate totals for debit
items.

Total items should equal the total batches.

I guess if I had relatively good XML parsing code, I could figure out
how

Jun 27 '08 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

22 posts views Thread by Ram Laxman | last post: by
3 posts views Thread by slylos | last post: by
AdrianH
5 posts views Thread by AdrianH | last post: by
AdrianH
1 post views Thread by AdrianH | last post: by
5 posts views Thread by goldtech | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.