473,561 Members | 3,336 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 "BatchTktAmount for
any <Batchelement s that may exist. There could be 1 or more...

As a verification, I may also want to add the <BATCH\Itemsele ments, 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>2008 0610:171706</StartTime>
<EndTime>200806 10:171747</EndTime>
<BusinessDate>2 0080610</BusinessDate>
<Device>26</Device>
<Site/>
<ProcType>Prime </ProcType>
<WorkTypeNumber >1</WorkTypeNumber>
<ClearingType>O utClearing</ClearingType>
<DebitsFirst>FA LSE</DebitsFirst>
<SortFamily>900 </SortFamily>
<Imaged>TRUE</Imaged>
<NbrOfBlocksInJ ob>1</NbrOfBlocksInJo b>
<CycleID>A</CycleID>
<Blocks>
<Block>
<BlkNbr>64</BlkNbr>
<BlkStartTime>2 0080610:171706</BlkStartTime>
<BlkEndTime>200 80610:171747</BlkEndTime>
<BlkSeqInJob> 1</BlkSeqInJob>
<BlkFrontImgFil eName>\\VMSERVE R1\MyApp\AllIte msExtract\G179B C\0064_5.fim</BlkFrontImgFile Name>
<BlkRearImgFile Name>\\VMSERVER 1\MyApp\AllItem sExtract\G179BC \0064_5.rim</BlkRearImgFileN ame>
<Batches>
<Batch>
<BatchNbr>1</BatchNbr>
<BranchData>
<BranchID>07901 0</BranchID>
<BranchDeviceID >79010</BranchDeviceID>
<BranchTill>0 </BranchTill>
<BranchBatchNbr >1</BranchBatchNbr>
<BranchBusiness Date>20080610</BranchBusinessD ate>
</BranchData>
<BatchTktAmount >617181.39</BatchTktAmount>
<BatchTktTC/>
<BatchTktAN/>
<BatchTktRT>444 444442</BatchTktRT>
<BatchTktAux/>
<Items>
<Item>
<ISN>79010000 3 </ISN>
<ImageDocID>124 78</ImageDocID>
<Gender>CR</Gender>
<Amount>17000.0 0</Amount>
<TC>009</TC>
<AN>012000015 3</AN>
<Fld4/>
<RT>5300-1000</RT>
<RIC/>
<Aux/>
<ACHCode>Check2 1</ACHCode>
<ACHConverted RT/>
<ACHConvertedAc count/>
<IsElectronic>F ALSE</IsElectronic>
<IsOnUs>TRUE</IsOnUs>
<IsDeleted>FALS E</IsDeleted>
<IsInsert>FALSE </IsInsert>
<IsCorrected>FA LSE</IsCorrected>
<IsReject>FALSE </IsReject>
<RejectReason>0 </RejectReason>
<OutsortReason> 0</OutsortReason>
<Availability>0 </Availability>
<AppCode>0</AppCode>
<SPSelector>100 0</SPSelector>
<Currency>USD </Currency>
<AdjustmentType >0</AdjustmentType>
<AdjustmentReas on>0</AdjustmentReaso n>
<Images>
<Image>
<ImageView>Fron t</ImageView>
<ImageType>CCIT TG4</ImageType>
<ImageOffSet>51 4</ImageOffSet>
<ImageLength>62 98</ImageLength>
</Image>
<Image>
<ImageView>Rear </ImageView>
<ImageType>CCIT TG4</ImageType>
<ImageOffSet>51 4</ImageOffSet>
<ImageLength>52 40</ImageLength>
</Image>
</Images>
<CustomerUserIn fo>
<Field1>t5300-1000t0120000153 o009</Field1>
<Field2>1001</Field2>
<Field3/>
<Field4/>
</CustomerUserInf o>
</Item>
<Item>
<ISN>79010000 4 </ISN>
<ImageDocID>124 79</ImageDocID>
<Gender>DR</Gender>
<Amount>17000.0 0</Amount>
<TC>1011</TC>
<AN>362343062 </AN>
<Fld4/>
<RT>999999999 </RT>
<RIC/>
<Aux/>
<ACHCode>Check2 1</ACHCode>
<ACHConverted RT/>
<ACHConvertedAc count/>
<IsElectronic>F ALSE</IsElectronic>
<IsOnUs>FALSE </IsOnUs>
<IsDeleted>FALS E</IsDeleted>
<IsInsert>FALSE </IsInsert>
<IsCorrected>FA LSE</IsCorrected>
<IsReject>FALSE </IsReject>
<RejectReason>0 </RejectReason>
<OutsortReason> 0</OutsortReason>
<Availability>0 </Availability>
<AppCode>0</AppCode>
<SPSelector>800 0</SPSelector>
<Currency>USD </Currency>
<AdjustmentType >0</AdjustmentType>
<AdjustmentReas on>0</AdjustmentReaso n>
<Images>
<Image>
<ImageView>Fron t</ImageView>
<ImageType>CCIT TG4</ImageType>
<ImageOffSet>68 12</ImageOffSet>
<ImageLength>76 24</ImageLength>
</Image>
<Image>
<ImageView>Rear </ImageView>
<ImageType>CCIT TG4</ImageType>
<ImageOffSet>57 54</ImageOffSet>
<ImageLength>28 20</ImageLength>
</Image>
</Images>
<CustomerUserIn fo>
<Field1>t031301 422t362343062o1 011</Field1>
<Field2>8000</Field2>
<Field3/>
<Field4>0011000 110000000000000 000</Field4>
</CustomerUserInf o>
</Item>
<Item>
<ISN>79010000 5 </ISN>
<ImageDocID>124 80</ImageDocID>
<Gender>CR</Gender>
<Amount>12405.1 8</Amount>
<TC>109</TC>
<AN>014002437 </AN>
<Fld4/>
<RT>5009-1000</RT>
<RIC/>
<Aux/>
<ACHCode>Check2 1</ACHCode>
<ACHConverted RT/>
<ACHConvertedAc count/>
<IsElectronic>F ALSE</IsElectronic>
<IsOnUs>TRUE</IsOnUs>
<IsDeleted>FALS E</IsDeleted>
<IsInsert>FALSE </IsInsert>
<IsCorrected>FA LSE</IsCorrected>
<IsReject>FALSE </IsReject>
<RejectReason>0 </RejectReason>
<OutsortReason> 0</OutsortReason>
<Availability>0 </Availability>
<AppCode>0</AppCode>
<SPSelector>100 0</SPSelector>
<Currency>USD </Currency>
<AdjustmentType >0</AdjustmentType>
<AdjustmentReas on>0</AdjustmentReaso n>
<Images>
<Image>
<ImageView>Fron t</ImageView>
<ImageType>CCIT TG4</ImageType>
<ImageOffSet>14 436</ImageOffSet>
<ImageLength>49 34</ImageLength>
</Image>
<Image>
<ImageView>Rear </ImageView>
<ImageType>CCIT TG4</ImageType>
<ImageOffSet>85 74</ImageOffSet>
<ImageLength>41 45</ImageLength>
</Image>
</Images>
<CustomerUserIn fo>
<Field1>t5009-1000t109</Field1>
<Field2>1003</Field2>
<Field3/>
<Field4/>
</CustomerUserInf o>
</Item>
<Item>
<ISN>79010000 6 </ISN>
<ImageDocID>124 81</ImageDocID>
<Gender>DR</Gender>
<Amount>1733.06 </Amount>
<TC/>
<AN>100241913 3</AN>
<Fld4/>
<RT>043301627 </RT>
<RIC/>
<Aux>0013866851 </Aux>
<ACHCode>Check2 1</ACHCode>
<ACHConverted RT/>
<ACHConvertedAc count/>
<IsElectronic>F ALSE</IsElectronic>
<IsOnUs>FALSE </IsOnUs>
<IsDeleted>FALS E</IsDeleted>
<IsInsert>FALSE </IsInsert>
<IsCorrected>FA LSE</IsCorrected>
<IsReject>FALSE </IsReject>
<RejectReason>0 </RejectReason>
<OutsortReason> 0</OutsortReason>
<Availability>0 </Availability>
<AppCode>0</AppCode>
<SPSelector>800 0</SPSelector>
<Currency>USD </Currency>
<AdjustmentType >0</AdjustmentType>
<AdjustmentReas on>0</AdjustmentReaso n>
<Images>
<Image>
<ImageView>Fron t</ImageView>
<ImageType>CCIT TG4</ImageType>
<ImageOffSet>19 370</ImageOffSet>
<ImageLength>10 443</ImageLength>
</Image>
<Image>
<ImageView>Rear </ImageView>
<ImageType>CCIT TG4</ImageType>
<ImageOffSet>12 719</ImageOffSet>
<ImageLength>51 43</ImageLength>
</Image>
</Images>
<CustomerUserIn fo>
<Field1>o001386 6851ot043301627 t1002419133o</Field1>
<Field2>8000</Field2>
<Field3/>
<Field4>0011000 110000000000000 000</Field4>
</CustomerUserInf o>
</Item>
<Item>
<ISN>79010000 7 </ISN>
<ImageDocID>124 82</ImageDocID>
<Gender>DR</Gender>
<Amount>10672.1 2</Amount>
<TC/>
<AN>009000091 </AN>
<Fld4/>
<RT>999999999 </RT>
<RIC/>
<Aux>1095468</Aux>
<ACHCode>Check2 1</ACHCode>
<ACHConverted RT/>
<ACHConvertedAc count/>
<IsElectronic>F ALSE</IsElectronic>
<IsOnUs>FALSE </IsOnUs>
<IsDeleted>FALS E</IsDeleted>
<IsInsert>FALSE </IsInsert>
<IsCorrected>FA LSE</IsCorrected>
<IsReject>FALSE </IsReject>
<RejectReason>0 </RejectReason>
<OutsortReason> 0</OutsortReason>
<Availability>0 </Availability>
<AppCode>0</AppCode>
<SPSelector>800 0</SPSelector>
<Currency>USD </Currency>
<AdjustmentType >0</AdjustmentType>
<AdjustmentReas on>0</AdjustmentReaso n>
<Images>
<Image>
<ImageView>Fron t</ImageView>
<ImageType>CCIT TG4</ImageType>
<ImageOffSet>29 813</ImageOffSet>
<ImageLength>22 934</ImageLength>
</Image>
<Image>
<ImageView>Rear </ImageView>
<ImageType>CCIT TG4</ImageType>
<ImageOffSet>17 862</ImageOffSet>
<ImageLength>18 116</ImageLength>
</Image>
</Images>
<CustomerUserIn fo>
<Field1>o109546 8ot031301422t00 9000091o</Field1>
<Field2>8000</Field2>
<Field3/>
<Field4>0011000 110000000000000 000</Field4>
</CustomerUserInf o>
</Item>
<Item>
<ISN>79010000 8 </ISN>
<ImageDocID>124 83</ImageDocID>
<Gender>CR</Gender>
<Amount>208000. 00</Amount>
<TC>009</TC>
<AN>010000014 0</AN>
<Fld4/>
<RT>031919186 </RT>
<RIC/>
<Aux>000033</Aux>
<ACHCode>Check2 1</ACHCode>
<ACHConverted RT/>
<ACHConvertedAc count/>
<IsElectronic>F ALSE</IsElectronic>
<IsOnUs>TRUE</IsOnUs>
<IsDeleted>FALS E</IsDeleted>
<IsInsert>FALSE </IsInsert>
<IsCorrected>FA LSE</IsCorrected>
<IsReject>FALSE </IsReject>
<RejectReason>0 </RejectReason>
<OutsortReason> 0</OutsortReason>
<Availability>0 </Availability>
<AppCode>0</AppCode>
<SPSelector>100 0</SPSelector>
<Currency>USD </Currency>
<AdjustmentType >0</AdjustmentType>
<AdjustmentReas on>0</AdjustmentReaso n>
<Images>
<Image>
<ImageView>Fron t</ImageView>
<ImageType>CCIT TG4</ImageType>
<ImageOffSet>52 747</ImageOffSet>
<ImageLength>61 16</ImageLength>
</Image>
<Image>
<ImageView>Rear </ImageView>
<ImageType>CCIT TG4</ImageType>
<ImageOffSet>35 978</ImageOffSet>
<ImageLength>31 03</ImageLength>
</Image>
</Images>
<CustomerUserIn fo>
<Field1>o000033 ot031919186t010 0000140o009</Field1>
<Field2>1001</Field2>
<Field3/>
<Field4>0011000 110000000000000 000</Field4>
</CustomerUserInf o>
</Item>
<Item>
<ISN>79010000 9 </ISN>
<ImageDocID>124 84</ImageDocID>
<Gender>DR</Gender>
<Amount>208000. 00</Amount>
<TC>500</TC>
<AN>139005009 8</AN>
<Fld4/>
<RT>5021-1000</RT>
<RIC/>
<Aux/>
<ACHCode>Check2 1</ACHCode>
<ACHConverted RT/>
<ACHConvertedAc count/>
<IsElectronic>F ALSE</IsElectronic>
<IsOnUs>TRUE</IsOnUs>
<IsDeleted>FALS E</IsDeleted>
<IsInsert>FALSE </IsInsert>
<IsCorrected>FA LSE</IsCorrected>
<IsReject>FALSE </IsReject>
<RejectReason>0 </RejectReason>
<OutsortReason> 0</OutsortReason>
<Availability>0 </Availability>
<AppCode>0</AppCode>
<SPSelector>200 0</SPSelector>
<Currency>USD </Currency>
<AdjustmentType >0</AdjustmentType>
<AdjustmentReas on>0</AdjustmentReaso n>
<Images>
<Image>
<ImageView>Fron t</ImageView>
<ImageType>CCIT TG4</ImageType>
<ImageOffSet>58 863</ImageOffSet>
<ImageLength>56 49</ImageLength>
</Image>
<Image>
<ImageView>Rear </ImageView>
<ImageType>CCIT TG4</ImageType>
<ImageOffSet>39 081</ImageOffSet>
<ImageLength>16 20</ImageLength>
</Image>
</Images>
<CustomerUserIn fo>
<Field1>t5021-1000t500</Field1>
<Field2>2006</Field2>
<Field3/>
<Field4/>
</CustomerUserInf o>
</Item>
<Item>
<ISN>79010001 0 </ISN>
<ImageDocID>124 85</ImageDocID>
<Gender>CR</Gender>
<Amount>5626.06 </Amount>
<TC>009</TC>
<AN>040000134 </AN>
<Fld4/>
<RT>5300-1000</RT>
<RIC/>
<Aux/>
<ACHCode>Check2 1</ACHCode>
<ACHConverted RT/>
<ACHConvertedAc count/>
<IsElectronic>F ALSE</IsElectronic>
<IsOnUs>TRUE</IsOnUs>
<IsDeleted>FALS E</IsDeleted>
<IsInsert>FALSE </IsInsert>
<IsCorrected>FA LSE</IsCorrected>
<IsReject>FALSE </IsReject>
<RejectReason>0 </RejectReason>
<OutsortReason> 0</OutsortReason>
<Availability>0 </Availability>
<AppCode>0</AppCode>
<SPSelector>100 0</SPSelector>
<Currency>USD </Currency>
<AdjustmentType >0</AdjustmentType>
<AdjustmentReas on>0</AdjustmentReaso n>
<Images>
<Image>
<ImageView>Fron t</ImageView>
<ImageType>CCIT TG4</ImageType>
<ImageOffSet>64 512</ImageOffSet>
<ImageLength>47 97</ImageLength>
</Image>
<Image>
<ImageView>Rear </ImageView>
<ImageType>CCIT TG4</ImageType>
<ImageOffSet>40 701</ImageOffSet>
<ImageLength>47 56</ImageLength>
</Image>
</Images>
<CustomerUserIn fo>
<Field1>t5300-1000t</Field1>
<Field2>1001</Field2>
<Field3/>
<Field4/>
</CustomerUserInf o>
</Item>
<Item>
<ISN>79010005 4 </ISN>
<ImageDocID>125 27</ImageDocID>
<Gender>CR</Gender>
<Amount>150.0 0</Amount>
<TC>400</TC>
<AN>782000000 1</AN>
<Fld4/>
<RT>5020-1000</RT>
<RIC/>
<Aux/>
<ACHCode>Check2 1</ACHCode>
<ACHConverted RT/>
<ACHConvertedAc count/>
<IsElectronic>F ALSE</IsElectronic>
<IsOnUs>TRUE</IsOnUs>
<IsDeleted>FALS E</IsDeleted>
<IsInsert>FALSE </IsInsert>
<IsCorrected>FA LSE</IsCorrected>
<IsReject>FALSE </IsReject>
<RejectReason>0 </RejectReason>
<OutsortReason> 0</OutsortReason>
<Availability>0 </Availability>
<AppCode>0</AppCode>
<SPSelector>100 0</SPSelector>
<Currency>USD </Currency>
<AdjustmentType >0</AdjustmentType>
<AdjustmentReas on>0</AdjustmentReaso n>
<Images>
<Image>
<ImageView>Fron t</ImageView>
<ImageType>CCIT TG4</ImageType>
<ImageOffSet>44 9337</ImageOffSet>
<ImageLength>53 84</ImageLength>
</Image>
<Image>
<ImageView>Rear </ImageView>
<ImageType>CCIT TG4</ImageType>
<ImageOffSet>25 0370</ImageOffSet>
<ImageLength>16 84</ImageLength>
</Image>
</Images>
<CustomerUserIn fo>
<Field1>t5020-1000t400</Field1>
<Field2>1006</Field2>
<Field3/>
<Field4/>
</CustomerUserInf o>
</Item>
<Item>
<ISN>79010005 5 </ISN>
<ImageDocID>125 28</ImageDocID>
<Gender>DR</Gender>
<Amount>150.0 0</Amount>
<TC>700</TC>
<AN>100101000 1</AN>
<Fld4/>
<RT>5011-0000</RT>
<RIC/>
<Aux/>
<ACHCode>Check2 1</ACHCode>
<ACHConverted RT/>
<ACHConvertedAc count/>
<IsElectronic>F ALSE</IsElectronic>
<IsOnUs>TRUE</IsOnUs>
<IsDeleted>FALS E</IsDeleted>
<IsInsert>FALSE </IsInsert>
<IsCorrected>FA LSE</IsCorrected>
<IsReject>FALSE </IsReject>
<RejectReason>0 </RejectReason>
<OutsortReason> 0</OutsortReason>
<Availability>0 </Availability>
<AppCode>0</AppCode>
<SPSelector>200 0</SPSelector>
<Currency>USD </Currency>
<AdjustmentType >0</AdjustmentType>
<AdjustmentReas on>0</AdjustmentReaso n>
<Images>
<Image>
<ImageView>Fron t</ImageView>
<ImageType>CCIT TG4</ImageType>
<ImageOffSet>45 4721</ImageOffSet>
<ImageLength>21 96</ImageLength>
</Image>
<Image>
<ImageView>Rear </ImageView>
<ImageType>CCIT TG4</ImageType>
<ImageOffSet>25 2054</ImageOffSet>
<ImageLength>17 34</ImageLength>
</Image>
</Images>
<CustomerUserIn fo>
<Field1>t5011-0000t1001010001 o700</Field1>
<Field2>2006</Field2>
<Field3/>
<Field4/>
</CustomerUserInf o>
</Item>
<Item>
<ISN>79010005 6 </ISN>
<ImageDocID>125 29</ImageDocID>
<Gender>CR</Gender>
<Amount>11190.1 5</Amount>
<TC>009</TC>
<AN>012000077 3</AN>
<Fld4/>
<RT>5300-1000</RT>
<RIC/>
<Aux/>
<ACHCode>Check2 1</ACHCode>
<ACHConverted RT/>
<ACHConvertedAc count/>
<IsElectronic>F ALSE</IsElectronic>
<IsOnUs>TRUE</IsOnUs>
<IsDeleted>FALS E</IsDeleted>
<IsInsert>FALSE </IsInsert>
<IsCorrected>FA LSE</IsCorrected>
<IsReject>FALSE </IsReject>
<RejectReason>0 </RejectReason>
<OutsortReason> 0</OutsortReason>
<Availability>0 </Availability>
<AppCode>0</AppCode>
<SPSelector>100 0</SPSelector>
<Currency>USD </Currency>
<AdjustmentType >0</AdjustmentType>
<AdjustmentReas on>0</AdjustmentReaso n>
<Images>
<Image>
<ImageView>Fron t</ImageView>
<ImageType>CCIT TG4</ImageType>
<ImageOffSet>45 6917</ImageOffSet>
<ImageLength>43 35</ImageLength>
</Image>
<Image>
<ImageView>Rear </ImageView>
<ImageType>CCIT TG4</ImageType>
<ImageOffSet>25 3788</ImageOffSet>
<ImageLength>41 01</ImageLength>
</Image>
</Images>
<CustomerUserIn fo>
<Field1>t5300-1000t009</Field1>
<Field2>1001</Field2>
<Field3/>
<Field4/>
</CustomerUserInf o>
</Item>
<Item>
<ISN>79010005 7 </ISN>
<ImageDocID>125 30</ImageDocID>
<Gender>DR</Gender>
<Amount>11190.1 5</Amount>
<TC/>
<AN>68001764644 391</AN>
<Fld4/>
<RT>102000979 </RT>
<RIC/>
<Aux>225127</Aux>
<ACHCode>Check2 1</ACHCode>
<ACHConverted RT/>
<ACHConvertedAc count/>
<IsElectronic>F ALSE</IsElectronic>
<IsOnUs>FALSE </IsOnUs>
<IsDeleted>FALS E</IsDeleted>
<IsInsert>FALSE </IsInsert>
<IsCorrected>FA LSE</IsCorrected>
<IsReject>FALSE </IsReject>
<RejectReason>0 </RejectReason>
<OutsortReason> 0</OutsortReason>
<Availability>0 </Availability>
<AppCode>0</AppCode>
<SPSelector>800 0</SPSelector>
<Currency>USD </Currency>
<AdjustmentType >0</AdjustmentType>
<AdjustmentReas on>0</AdjustmentReaso n>
<Images>
<Image>
<ImageView>Fron t</ImageView>
<ImageType>CCIT TG4</ImageType>
<ImageOffSet>46 1252</ImageOffSet>
<ImageLength>17 986</ImageLength>
</Image>
<Image>
<ImageView>Rear </ImageView>
<ImageType>CCIT TG4</ImageType>
<ImageOffSet>25 7889</ImageOffSet>
<ImageLength>84 32</ImageLength>
</Image>
</Images>
<CustomerUserIn fo>
<Field1>o225127 ot102000979t680 01764644391o</Field1>
<Field2>8000</Field2>
<Field3/>
<Field4>0011000 110000000000000 000</Field4>
</CustomerUserInf o>
</Item>
<Item>
<ISN>79010005 8 </ISN>
<ImageDocID>125 31</ImageDocID>
<Gender>DR</Gender>
<Amount>100.0 0</Amount>
<TC>1436</TC>
<AN>00496939561 6</AN>
<Fld4/>
<RT>122400724 </RT>
<RIC/>
<Aux/>
<ACHCode>Check2 1</ACHCode>
<ACHConverted RT/>
<ACHConvertedAc count/>
<IsElectronic>F ALSE</IsElectronic>
<IsOnUs>FALSE </IsOnUs>
<IsDeleted>TRUE </IsDeleted>
<IsInsert>FALSE </IsInsert>
<IsCorrected>FA LSE</IsCorrected>
<IsReject>FALSE </IsReject>
<RejectReason>0 </RejectReason>
<OutsortReason> 0</OutsortReason>
<Availability>0 </Availability>
<AppCode>0</AppCode>
<SPSelector>800 0</SPSelector>
<Currency>USD </Currency>
<AdjustmentType >0</AdjustmentType>
<AdjustmentReas on>0</AdjustmentReaso n>
<Images>
<Image>
<ImageView>Fron t</ImageView>
<ImageType>CCIT TG4</ImageType>
<ImageOffSet>47 9238</ImageOffSet>
<ImageLength>13 393</ImageLength>
</Image>
<Image>
<ImageView>Rear </ImageView>
<ImageType>CCIT TG4</ImageType>
<ImageOffSet>26 6321</ImageOffSet>
<ImageLength>28 24</ImageLength>
</Image>
</Images>
<CustomerUserIn fo>
<Field1>t122400 724t00496939561 6o1436</Field1>
<Field2>8000</Field2>
<Field3/>
<Field4>0011000 110000000000000 000</Field4>
</CustomerUserInf o>
</Item>
<Item>
<ISN>79010005 9 </ISN>
<ImageDocID>125 32</ImageDocID>
<Gender>CR</Gender>
<Amount>350000. 00</Amount>
<TC>009</TC>
<AN>010000014 0</AN>
<Fld4/>
<RT>031919186 </RT>
<RIC/>
<Aux>000035</Aux>
<ACHCode>Check2 1</ACHCode>
<ACHConverted RT/>
<ACHConvertedAc count/>
<IsElectronic>F ALSE</IsElectronic>
<IsOnUs>TRUE</IsOnUs>
<IsDeleted>FALS E</IsDeleted>
<IsInsert>FALSE </IsInsert>
<IsCorrected>FA LSE</IsCorrected>
<IsReject>FALSE </IsReject>
<RejectReason>0 </RejectReason>
<OutsortReason> 0</OutsortReason>
<Availability>0 </Availability>
<AppCode>0</AppCode>
<SPSelector>100 0</SPSelector>
<Currency>USD </Currency>
<AdjustmentType >0</AdjustmentType>
<AdjustmentReas on>0</AdjustmentReaso n>
<Images>
<Image>
<ImageView>Fron t</ImageView>
<ImageType>CCIT TG4</ImageType>
<ImageOffSet>49 2631</ImageOffSet>
<ImageLength>54 47</ImageLength>
</Image>
<Image>
<ImageView>Rear </ImageView>
<ImageType>CCIT TG4</ImageType>
<ImageOffSet>26 9145</ImageOffSet>
<ImageLength>30 26</ImageLength>
</Image>
</Images>
<CustomerUserIn fo>
<Field1>o000035 ot031919186t010 0000140o009</Field1>
<Field2>1001</Field2>
<Field3/>
<Field4>0011000 110000000000000 000</Field4>
</CustomerUserInf o>
</Item>
<Item>
<ISN>79010006 0 </ISN>
<ImageDocID>125 33</ImageDocID>
<Gender>DR</Gender>
<Amount>350000. 00</Amount>
<TC>500</TC>
<AN>139005009 8</AN>
<Fld4/>
<RT>5021-1000</RT>
<RIC/>
<Aux/>
<ACHCode>Check2 1</ACHCode>
<ACHConverted RT/>
<ACHConvertedAc count/>
<IsElectronic>F ALSE</IsElectronic>
<IsOnUs>TRUE</IsOnUs>
<IsDeleted>FALS E</IsDeleted>
<IsInsert>FALSE </IsInsert>
<IsCorrected>FA LSE</IsCorrected>
<IsReject>FALSE </IsReject>
<RejectReason>0 </RejectReason>
<OutsortReason> 0</OutsortReason>
<Availability>0 </Availability>
<AppCode>0</AppCode>
<SPSelector>200 0</SPSelector>
<Currency>USD </Currency>
<AdjustmentType >0</AdjustmentType>
<AdjustmentReas on>0</AdjustmentReaso n>
<Images>
<Image>
<ImageView>Fron t</ImageView>
<ImageType>CCIT TG4</ImageType>
<ImageOffSet>49 8078</ImageOffSet>
<ImageLength>61 15</ImageLength>
</Image>
<Image>
<ImageView>Rear </ImageView>
<ImageType>CCIT TG4</ImageType>
<ImageOffSet>27 2171</ImageOffSet>
<ImageLength>15 78</ImageLength>
</Image>
</Images>
<CustomerUserIn fo>
<Field1>t5021-1000t500</Field1>
<Field2>2006</Field2>
<Field3/>
<Field4/>
</CustomerUserInf o>
</Item>
<Item>
<ISN>79010006 1 </ISN>
<ImageDocID>125 34</ImageDocID>
<Gender>CR</Gender>
<Amount>1750.00 </Amount>
<TC>400</TC>
<AN>177001009 8</AN>
<Fld4/>
<RT>5020-1000</RT>
<RIC/>
<Aux/>
<ACHCode>Check2 1</ACHCode>
<ACHConverted RT/>
<ACHConvertedAc count/>
<IsElectronic>F ALSE</IsElectronic>
<IsOnUs>TRUE</IsOnUs>
<IsDeleted>FALS E</IsDeleted>
<IsInsert>FALSE </IsInsert>
<IsCorrected>FA LSE</IsCorrected>
<IsReject>FALSE </IsReject>
<RejectReason>0 </RejectReason>
<OutsortReason> 0</OutsortReason>
<Availability>0 </Availability>
<AppCode>0</AppCode>
<SPSelector>100 0</SPSelector>
<Currency>USD </Currency>
<AdjustmentType >0</AdjustmentType>
<AdjustmentReas on>0</AdjustmentReaso n>
<Images>
<Image>
<ImageView>Fron t</ImageView>
<ImageType>CCIT TG4</ImageType>
<ImageOffSet>50 4193</ImageOffSet>
<ImageLength>56 50</ImageLength>
</Image>
<Image>
<ImageView>Rear </ImageView>
<ImageType>CCIT TG4</ImageType>
<ImageOffSet>27 3749</ImageOffSet>
<ImageLength>29 63</ImageLength>
</Image>
</Images>
<CustomerUserIn fo>
<Field1>t5020-1000t400</Field1>
<Field2>1006</Field2>
<Field3/>
<Field4/>
</CustomerUserInf o>
</Item>
<Item>
<ISN>79010006 2 </ISN>
<ImageDocID>125 35</ImageDocID>
<Gender>DR</Gender>
<Amount>1750.00 </Amount>
<TC/>
<AN>20000125426 51</AN>
<Fld4/>
<RT>031000503 </RT>
<RIC/>
<Aux>017371</Aux>
<ACHCode>Check2 1</ACHCode>
<ACHConverted RT/>
<ACHConvertedAc count/>
<IsElectronic>F ALSE</IsElectronic>
<IsOnUs>FALSE </IsOnUs>
<IsDeleted>FALS E</IsDeleted>
<IsInsert>FALSE </IsInsert>
<IsCorrected>FA LSE</IsCorrected>
<IsReject>FALSE </IsReject>
<RejectReason>0 </RejectReason>
<OutsortReason> 0</OutsortReason>
<Availability>0 </Availability>
<AppCode>0</AppCode>
<SPSelector>800 0</SPSelector>
<Currency>USD </Currency>
<AdjustmentType >0</AdjustmentType>
<AdjustmentReas on>0</AdjustmentReaso n>
<Images>
<Image>
<ImageView>Fron t</ImageView>
<ImageType>CCIT TG4</ImageType>
<ImageOffSet>50 9843</ImageOffSet>
<ImageLength>10 988</ImageLength>
</Image>
<Image>
<ImageView>Rear </ImageView>
<ImageType>CCIT TG4</ImageType>
<ImageOffSet>27 6712</ImageOffSet>
<ImageLength>23 74</ImageLength>
</Image>
</Images>
<CustomerUserIn fo>
<Field1>o017371 ot031000503t200 0012542651o</Field1>
<Field2>8000</Field2>
<Field3/>
<Field4>0011000 110000000000000 000</Field4>
</CustomerUserInf o>
</Item>
<Item>
<ISN>79010006 3 </ISN>
<ImageDocID>125 36</ImageDocID>
<Gender>CR</Gender>
<Amount>60.00 </Amount>
<TC>600</TC>
<AN>100101000 1</AN>
<Fld4/>
<RT>5010-0000</RT>
<RIC/>
<Aux/>
<ACHCode>Check2 1</ACHCode>
<ACHConverted RT/>
<ACHConvertedAc count/>
<IsElectronic>F ALSE</IsElectronic>
<IsOnUs>TRUE</IsOnUs>
<IsDeleted>FALS E</IsDeleted>
<IsInsert>FALSE </IsInsert>
<IsCorrected>FA LSE</IsCorrected>
<IsReject>FALSE </IsReject>
<RejectReason>0 </RejectReason>
<OutsortReason> 0</OutsortReason>
<Availability>0 </Availability>
<AppCode>0</AppCode>
<SPSelector>100 0</SPSelector>
<Currency>USD </Currency>
<AdjustmentType >0</AdjustmentType>
<AdjustmentReas on>0</AdjustmentReaso n>
<Images>
<Image>
<ImageView>Fron t</ImageView>
<ImageType>CCIT TG4</ImageType>
<ImageOffSet>52 0831</ImageOffSet>
<ImageLength>26 54</ImageLength>
</Image>
<Image>
<ImageView>Rear </ImageView>
<ImageType>CCIT TG4</ImageType>
<ImageOffSet>27 9086</ImageOffSet>
<ImageLength>23 14</ImageLength>
</Image>
</Images>
<CustomerUserIn fo>
<Field1>t5010-0000t1001010001 o600</Field1>
<Field2>1006</Field2>
<Field3/>
<Field4/>
</CustomerUserInf o>
</Item>
<Item>
<ISN>79010006 4 </ISN>
<ImageDocID>125 37</ImageDocID>
<Gender>DR</Gender>
<Amount>60.00 </Amount>
<TC>046</TC>
<AN>012000010 4</AN>
<Fld4/>
<RT>5301-1000</RT>
<RIC/>
<Aux/>
<ACHCode>Check2 1</ACHCode>
<ACHConverted RT/>
<ACHConvertedAc count/>
<IsElectronic>F ALSE</IsElectronic>
<IsOnUs>TRUE</IsOnUs>
<IsDeleted>FALS E</IsDeleted>
<IsInsert>FALSE </IsInsert>
<IsCorrected>FA LSE</IsCorrected>
<IsReject>FALSE </IsReject>
<RejectReason>0 </RejectReason>
<OutsortReason> 0</OutsortReason>
<Availability>0 </Availability>
<AppCode>0</AppCode>
<SPSelector>200 0</SPSelector>
<Currency>USD </Currency>
<AdjustmentType >0</AdjustmentType>
<AdjustmentReas on>0</AdjustmentReaso n>
<Images>
<Image>
<ImageView>Fron t</ImageView>
<ImageType>CCIT TG4</ImageType>
<ImageOffSet>52 3485</ImageOffSet>
<ImageLength>38 94</ImageLength>
</Image>
<Image>
<ImageView>Rear </ImageView>
<ImageType>CCIT TG4</ImageType>
<ImageOffSet>28 1400</ImageOffSet>
<ImageLength>27 95</ImageLength>
</Image>
</Images>
<CustomerUserIn fo>
<Field1>t5301-1000t046</Field1>
<Field2>2001</Field2>
<Field3/>
<Field4/>
</CustomerUserInf o>
</Item>
</Items>
</Batch>
</Batches>
<BatchCount>1 </BatchCount>
</Block>
</Blocks>
<BlockCount>1 </BlockCount>
</Job>
</Jobs>
</FileExchange>

Jun 27 '08 #1
6 2966
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****@discuss ions.microsoft. comwrote in message
news:6B******** *************** ***********@mic rosoft.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 <Batchelement s that may exist. There could be 1 or more...

As a verification, I may also want to add the <BATCH\Itemsele ments,
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>2008 0610:171706</StartTime>
<EndTime>200806 10:171747</EndTime>
<BusinessDate>2 0080610</BusinessDate>
<Device>26</Device>
<Site/>
<ProcType>Prime </ProcType>
<WorkTypeNumber >1</WorkTypeNumber>
<ClearingType>O utClearing</ClearingType>
<DebitsFirst>FA LSE</DebitsFirst>
<SortFamily>900 </SortFamily>
<Imaged>TRUE</Imaged>
<NbrOfBlocksInJ ob>1</NbrOfBlocksInJo b>
<CycleID>A</CycleID>
<Blocks>
<Block>
<BlkNbr>64</BlkNbr>
<BlkStartTime>2 0080610:171706</BlkStartTime>
<BlkEndTime>200 80610:171747</BlkEndTime>
<BlkSeqInJob> 1</BlkSeqInJob>
<BlkFrontImgFil eName>\\VMSERVE R1\MyApp\AllIte msExtract\G179B C\0064_5.fim</BlkFrontImgFile Name>
<BlkRearImgFile Name>\\VMSERVER 1\MyApp\AllItem sExtract\G179BC \0064_5.rim</BlkRearImgFileN ame>
<Batches>
<Batch>
<BatchNbr>1</BatchNbr>
<BranchData>
<BranchID>07901 0</BranchID>
<BranchDeviceID >79010</BranchDeviceID>
<BranchTill>0 </BranchTill>
<BranchBatchNbr >1</BranchBatchNbr>
<BranchBusiness Date>20080610</BranchBusinessD ate>
</BranchData>
<BatchTktAmount >617181.39</BatchTktAmount>
<BatchTktTC/>
<BatchTktAN/>
<BatchTktRT>444 444442</BatchTktRT>
<BatchTktAux/>
<Items>
<Item>
<ISN>79010000 3 </ISN>
<ImageDocID>124 78</ImageDocID>
<Gender>CR</Gender>
<Amount>17000.0 0</Amount>
<TC>009</TC>
<AN>012000015 3</AN>
<Fld4/>
<RT>5300-1000</RT>
<RIC/>
<Aux/>
<ACHCode>Check2 1</ACHCode>
<ACHConverted RT/>
<ACHConvertedAc count/>
<IsElectronic>F ALSE</IsElectronic>
<IsOnUs>TRUE</IsOnUs>
<IsDeleted>FALS E</IsDeleted>
<IsInsert>FALSE </IsInsert>
<IsCorrected>FA LSE</IsCorrected>
<IsReject>FALSE </IsReject>
<RejectReason>0 </RejectReason>
<OutsortReason> 0</OutsortReason>
<Availability>0 </Availability>
<AppCode>0</AppCode>
<SPSelector>100 0</SPSelector>
<Currency>USD </Currency>
<AdjustmentType >0</AdjustmentType>
<AdjustmentReas on>0</AdjustmentReaso n>
<Images>
<Image>
<ImageView>Fron t</ImageView>
<ImageType>CCIT TG4</ImageType>
<ImageOffSet>51 4</ImageOffSet>
<ImageLength>62 98</ImageLength>
</Image>
<Image>
<ImageView>Rear </ImageView>
<ImageType>CCIT TG4</ImageType>
<ImageOffSet>51 4</ImageOffSet>
<ImageLength>52 40</ImageLength>
</Image>
</Images>
<CustomerUserIn fo>
<Field1>t5300-1000t0120000153 o009</Field1>
<Field2>1001</Field2>
<Field3/>
<Field4/>
</CustomerUserInf o>
</Item>
<Item>
<ISN>79010000 4 </ISN>
<ImageDocID>124 79</ImageDocID>
<Gender>DR</Gender>
<Amount>17000.0 0</Amount>
<TC>1011</TC>
<AN>362343062 </AN>
<Fld4/>
<RT>999999999 </RT>
<RIC/>
<Aux/>
<ACHCode>Check2 1</ACHCode>
<ACHConverted RT/>
<ACHConvertedAc count/>
<IsElectronic>F ALSE</IsElectronic>
<IsOnUs>FALSE </IsOnUs>
<IsDeleted>FALS E</IsDeleted>
<IsInsert>FALSE </IsInsert>
<IsCorrected>FA LSE</IsCorrected>
<IsReject>FALSE </IsReject>
<RejectReason>0 </RejectReason>
<OutsortReason> 0</OutsortReason>
<Availability>0 </Availability>
<AppCode>0</AppCode>
<SPSelector>800 0</SPSelector>
<Currency>USD </Currency>
<AdjustmentType >0</AdjustmentType>
<AdjustmentReas on>0</AdjustmentReaso n>
<Images>
<Image>
<ImageView>Fron t</ImageView>
<ImageType>CCIT TG4</ImageType>
<ImageOffSet>68 12</ImageOffSet>
<ImageLength>76 24</ImageLength>
</Image>
<Image>
<ImageView>Rear </ImageView>
<ImageType>CCIT TG4</ImageType>
<ImageOffSet>57 54</ImageOffSet>
<ImageLength>28 20</ImageLength>
</Image>
</Images>
<CustomerUserIn fo>
<Field1>t031301 422t362343062o1 011</Field1>
<Field2>8000</Field2>
<Field3/>
<Field4>0011000 110000000000000 000</Field4>
</CustomerUserInf o>
</Item>
<Item>
<ISN>79010000 5 </ISN>
<ImageDocID>124 80</ImageDocID>
<Gender>CR</Gender>
<Amount>12405.1 8</Amount>
<TC>109</TC>
<AN>014002437 </AN>
<Fld4/>
<RT>5009-1000</RT>
<RIC/>
<Aux/>
<ACHCode>Check2 1</ACHCode>
<ACHConverted RT/>
<ACHConvertedAc count/>
<IsElectronic>F ALSE</IsElectronic>
<IsOnUs>TRUE</IsOnUs>
<IsDeleted>FALS E</IsDeleted>
<IsInsert>FALSE </IsInsert>
<IsCorrected>FA LSE</IsCorrected>
<IsReject>FALSE </IsReject>
<RejectReason>0 </RejectReason>
<OutsortReason> 0</OutsortReason>
<Availability>0 </Availability>
<AppCode>0</AppCode>
<SPSelector>100 0</SPSelector>
<Currency>USD </Currency>
<AdjustmentType >0</AdjustmentType>
<AdjustmentReas on>0</AdjustmentReaso n>
<Images>
<Image>
<ImageView>Fron t</ImageView>
<ImageType>CCIT TG4</ImageType>
<ImageOffSet>14 436</ImageOffSet>
<ImageLength>49 34</ImageLength>
</Image>
<Image>
<ImageView>Rear </ImageView>
<ImageType>CCIT TG4</ImageType>
<ImageOffSet>85 74</ImageOffSet>
<ImageLength>41 45</ImageLength>
</Image>
</Images>
<CustomerUserIn fo>
<Field1>t5009-1000t109</Field1>
<Field2>1003</Field2>
<Field3/>
<Field4/>
</CustomerUserInf o>
</Item>
<Item>
<ISN>79010000 6 </ISN>
<ImageDocID>124 81</ImageDocID>
<Gender>DR</Gender>
<Amount>1733.06 </Amount>
<TC/>
<AN>100241913 3</AN>
<Fld4/>
<RT>043301627 </RT>
<RIC/>
<Aux>0013866851 </Aux>
<ACHCode>Check2 1</ACHCode>
<ACHConverted RT/>
<ACHConvertedAc count/>
<IsElectronic>F ALSE</IsElectronic>
<IsOnUs>FALSE </IsOnUs>
<IsDeleted>FALS E</IsDeleted>
<IsInsert>FALSE </IsInsert>
<IsCorrected>FA LSE</IsCorrected>
<IsReject>FALSE </IsReject>
<RejectReason>0 </RejectReason>
<OutsortReason> 0</OutsortReason>
<Availability>0 </Availability>
<AppCode>0</AppCode>
<SPSelector>800 0</SPSelector>
<Currency>USD </Currency>
<AdjustmentType >0</AdjustmentType>
<AdjustmentReas on>0</AdjustmentReaso n>
<Images>
<Image>
<ImageView>Fron t</ImageView>
<ImageType>CCIT TG4</ImageType>
<ImageOffSet>19 370</ImageOffSet>
<ImageLength>10 443</ImageLength>
</Image>
<Image>
<ImageView>Rear </ImageView>
<ImageType>CCIT TG4</ImageType>
<ImageOffSet>12 719</ImageOffSet>
<ImageLength>51 43</ImageLength>
</Image>
</Images>
<CustomerUserIn fo>
<Field1>o001386 6851ot043301627 t1002419133o</Field1>
<Field2>8000</Field2>
<Field3/>
<Field4>0011000 110000000000000 000</Field4>
</CustomerUserInf o>
</Item>
<Item>
<ISN>79010000 7 </ISN>
<ImageDocID>124 82</ImageDocID>
<Gender>DR</Gender>
<Amount>10672.1 2</Amount>
<TC/>
<AN>009000091 </AN>
<Fld4/>
<RT>999999999 </RT>
<RIC/>
<Aux>1095468</Aux>
<ACHCode>Check2 1</ACHCode>
<ACHConverted RT/>
<ACHConvertedAc count/>
<IsElectronic>F ALSE</IsElectronic>
<IsOnUs>FALSE </IsOnUs>
<IsDeleted>FALS E</IsDeleted>
<IsInsert>FALSE </IsInsert>
<IsCorrected>FA LSE</IsCorrected>
<IsReject>FALSE </IsReject>
<RejectReason>0 </RejectReason>
<OutsortReason> 0</OutsortReason>
<Availability>0 </Availability>
<AppCode>0</AppCode>
<SPSelector>800 0</SPSelector>
<Currency>USD </Currency>
<AdjustmentType >0</AdjustmentType>
<AdjustmentReas on>0</AdjustmentReaso n>
<Images>
<Image>
<ImageView>Fron t</ImageView>
<ImageType>CCIT TG4</ImageType>
<ImageOffSet>29 813</ImageOffSet>
<ImageLength>22 934</ImageLength>
</Image>
<Image>
<ImageView>Rear </ImageView>
<ImageType>CCIT TG4</ImageType>
<ImageOffSet>17 862</ImageOffSet>
<ImageLength>18 116</ImageLength>
</Image>
</Images>
<CustomerUserIn fo>
<Field1>o109546 8ot031301422t00 9000091o</Field1>
<Field2>8000</Field2>
<Field3/>
<Field4>0011000 110000000000000 000</Field4>
</CustomerUserInf o>
</Item>
<Item>
<ISN>79010000 8 </ISN>
<ImageDocID>124 83</ImageDocID>
<Gender>CR</Gender>
<Amount>208000. 00</Amount>
<TC>009</TC>
<AN>010000014 0</AN>
<Fld4/>
<RT>031919186 </RT>
<RIC/>
<Aux>000033</Aux>
<ACHCode>Check2 1</ACHCode>
<ACHConverted RT/>
<ACHConvertedAc count/>
<IsElectronic>F ALSE</IsElectronic>
<IsOnUs>TRUE</IsOnUs>
<IsDeleted>FALS E</IsDeleted>
<IsInsert>FALSE </IsInsert>
<IsCorrected>FA LSE</IsCorrected>
<IsReject>FALSE </IsReject>
<RejectReason>0 </RejectReason>
<OutsortReason> 0</OutsortReason>
<Availability>0 </Availability>
<AppCode>0</AppCode>
<SPSelector>100 0</SPSelector>
<Currency>USD </Currency>
<AdjustmentType >0</AdjustmentType>
<AdjustmentReas on>0</AdjustmentReaso n>
<Images>
<Image>
<ImageView>Fron t</ImageView>
<ImageType>CCIT TG4</ImageType>
<ImageOffSet>52 747</ImageOffSet>
<ImageLength>61 16</ImageLength>
</Image>
<Image>
<ImageView>Rear </ImageView>
<ImageType>CCIT TG4</ImageType>
<ImageOffSet>35 978</ImageOffSet>
<ImageLength>31 03</ImageLength>
</Image>
</Images>
<CustomerUserIn fo>
<Field1>o000033 ot031919186t010 0000140o009</Field1>
<Field2>1001</Field2>
<Field3/>
<Field4>0011000 110000000000000 000</Field4>
</CustomerUserInf o>
</Item>
<Item>
<ISN>79010000 9 </ISN>
<ImageDocID>124 84</ImageDocID>
<Gender>DR</Gender>
<Amount>208000. 00</Amount>
<TC>500</TC>
<AN>139005009 8</AN>
<Fld4/>
<RT>5021-1000</RT>
<RIC/>
<Aux/>
<ACHCode>Check2 1</ACHCode>
<ACHConverted RT/>
<ACHConvertedAc count/>
<IsElectronic>F ALSE</IsElectronic>
<IsOnUs>TRUE</IsOnUs>
<IsDeleted>FALS E</IsDeleted>
<IsInsert>FALSE </IsInsert>
<IsCorrected>FA LSE</IsCorrected>
<IsReject>FALSE </IsReject>
<RejectReason>0 </RejectReason>
<OutsortReason> 0</OutsortReason>
<Availability>0 </Availability>
<AppCode>0</AppCode>
<SPSelector>200 0</SPSelector>
<Currency>USD </Currency>
<AdjustmentType >0</AdjustmentType>
<AdjustmentReas on>0</AdjustmentReaso n>
<Images>
<Image>
<ImageView>Fron t</ImageView>
<ImageType>CCIT TG4</ImageType>
<ImageOffSet>58 863</ImageOffSet>
<ImageLength>56 49</ImageLength>
</Image>
<Image>
<ImageView>Rear </ImageView>
<ImageType>CCIT TG4</ImageType>
<ImageOffSet>39 081</ImageOffSet>
<ImageLength>16 20</ImageLength>
</Image>
</Images>
<CustomerUserIn fo>
<Field1>t5021-1000t500</Field1>
<Field2>2006</Field2>
<Field3/>
<Field4/>
</CustomerUserInf o>
</Item>
<Item>
<ISN>79010001 0 </ISN>
<ImageDocID>124 85</ImageDocID>
<Gender>CR</Gender>
<Amount>5626.06 </Amount>
<TC>009</TC>
<AN>040000134 </AN>
<Fld4/>
<RT>5300-1000</RT>
<RIC/>
<Aux/>
<ACHCode>Check2 1</ACHCode>
<ACHConverted RT/>
<ACHConvertedAc count/>
<IsElectronic>F ALSE</IsElectronic>
<IsOnUs>TRUE</IsOnUs>
<IsDeleted>FALS E</IsDeleted>
<IsInsert>FALSE </IsInsert>
<IsCorrected>FA LSE</IsCorrected>
<IsReject>FALSE </IsReject>
<RejectReason>0 </RejectReason>
<OutsortReason> 0</OutsortReason>
<Availability>0 </Availability>
<AppCode>0</AppCode>
<SPSelector>100 0</SPSelector>
<Currency>USD </Currency>
<AdjustmentType >0</AdjustmentType>
<AdjustmentReas on>0</AdjustmentReaso n>
<Images>
<Image>
<ImageView>Fron t</ImageView>
<ImageType>CCIT TG4</ImageType>
<ImageOffSet>64 512</ImageOffSet>
<ImageLength>47 97</ImageLength>
</Image>
<Image>
<ImageView>Rear </ImageView>
<ImageType>CCIT TG4</ImageType>
<ImageOffSet>40 701</ImageOffSet>
<ImageLength>47 56</ImageLength>
</Image>
</Images>
<CustomerUserIn fo>
<Field1>t5300-1000t</Field1>
<Field2>1001</Field2>
<Field3/>
<Field4/>
</CustomerUserInf o>
</Item>
<Item>
<ISN>79010005 4 </ISN>
<ImageDocID>125 27</ImageDocID>
<Gender>CR</Gender>
<Amount>150.0 0</Amount>
<TC>400</TC>
<AN>782000000 1</AN>
<Fld4/>
<RT>5020-1000</RT>
<RIC/>
<Aux/>
<ACHCode>Check2 1</ACHCode>
<ACHConverted RT/>
<ACHConvertedAc count/>
<IsElectronic>F ALSE</IsElectronic>
<IsOnUs>TRUE</IsOnUs>
<IsDeleted>FALS E</IsDeleted>
<IsInsert>FALSE </IsInsert>
<IsCorrected>FA LSE</IsCorrected>
<IsReject>FALSE </IsReject>
<RejectReason>0 </RejectReason>
<OutsortReason> 0</OutsortReason>
<Availability>0 </Availability>
<AppCode>0</AppCode>
<SPSelector>100 0</SPSelector>
<Currency>USD </Currency>
<AdjustmentType >0</AdjustmentType>
<AdjustmentReas on>0</AdjustmentReaso n>
<Images>
<Image>
<ImageView>Fron t</ImageView>
<ImageType>CCIT TG4</ImageType>
<ImageOffSet>44 9337</ImageOffSet>
<ImageLength>53 84</ImageLength>
</Image>
<Image>
<ImageView>Rear </ImageView>
<ImageType>CCIT TG4</ImageType>
<ImageOffSet>25 0370</ImageOffSet>
<ImageLength>16 84</ImageLength>
</Image>
</Images>
<CustomerUserIn fo>
<Field1>t5020-1000t400</Field1>
<Field2>1006</Field2>
<Field3/>
<Field4/>
</CustomerUserInf o>
</Item>
<Item>
<ISN>79010005 5 </ISN>
<ImageDocID>125 28</ImageDocID>
<Gender>DR</Gender>
<Amount>150.0 0</Amount>
<TC>700</TC>
<AN>100101000 1</AN>
<Fld4/>
<RT>5011-0000</RT>
<RIC/>
<Aux/>
<ACHCode>Check2 1</ACHCode>
<ACHConverted RT/>
<ACHConvertedAc count/>
<IsElectronic>F ALSE</IsElectronic>
<IsOnUs>TRUE</IsOnUs>
<IsDeleted>FALS E</IsDeleted>
<IsInsert>FALSE </IsInsert>
<IsCorrected>FA LSE</IsCorrected>
<IsReject>FALSE </IsReject>
<RejectReason>0 </RejectReason>
<OutsortReason> 0</OutsortReason>
<Availability>0 </Availability>
<AppCode>0</AppCode>
<SPSelector>200 0</SPSelector>
<Currency>USD </Currency>
<AdjustmentType >0</AdjustmentType>
<AdjustmentReas on>0</AdjustmentReaso n>
<Images>
<Image>
<ImageView>Fron t</ImageView>
<ImageType>CCIT TG4</ImageType>
<ImageOffSet>45 4721</ImageOffSet>
<ImageLength>21 96</ImageLength>
</Image>
<Image>
<ImageView>Rear </ImageView>
<ImageType>CCIT TG4</ImageType>
<ImageOffSet>25 2054</ImageOffSet>
<ImageLength>17 34</ImageLength>
</Image>
</Images>
<CustomerUserIn fo>
<Field1>t5011-0000t1001010001 o700</Field1>
<Field2>2006</Field2>
<Field3/>
<Field4/>
</CustomerUserInf o>
</Item>
<Item>
<ISN>79010005 6 </ISN>
<ImageDocID>125 29</ImageDocID>
<Gender>CR</Gender>
<Amount>11190.1 5</Amount>
<TC>009</TC>
<AN>012000077 3</AN>
<Fld4/>
<RT>5300-1000</RT>
<RIC/>
<Aux/>
<ACHCode>Check2 1</ACHCode>
<ACHConverted RT/>
<ACHConvertedAc count/>
<IsElectronic>F ALSE</IsElectronic>
<IsOnUs>TRUE</IsOnUs>
<IsDeleted>FALS E</IsDeleted>
<IsInsert>FALSE </IsInsert>
<IsCorrected>FA LSE</IsCorrected>
<IsReject>FALSE </IsReject>
<RejectReason>0 </RejectReason>
<OutsortReason> 0</OutsortReason>
<Availability>0 </Availability>
<AppCode>0</AppCode>
<SPSelector>100 0</SPSelector>
<Currency>USD </Currency>
<AdjustmentType >0</AdjustmentType>
<AdjustmentReas on>0</AdjustmentReaso n>
<Images>
<Image>
<ImageView>Fron t</ImageView>
<ImageType>CCIT TG4</ImageType>
<ImageOffSet>45 6917</ImageOffSet>
<ImageLength>43 35</ImageLength>
</Image>
<Image>
<ImageView>Rear </ImageView>
<ImageType>CCIT TG4</ImageType>
<ImageOffSet>25 3788</ImageOffSet>
<ImageLength>41 01</ImageLength>
</Image>
</Images>
<CustomerUserIn fo>
<Field1>t5300-1000t009</Field1>
<Field2>1001</Field2>
<Field3/>
<Field4/>
</CustomerUserInf o>
</Item>
<Item>
<ISN>79010005 7 </ISN>
<ImageDocID>125 30</ImageDocID>
<Gender>DR</Gender>
<Amount>11190.1 5</Amount>
<TC/>
<AN>68001764644 391</AN>
<Fld4/>
<RT>102000979 </RT>
<RIC/>
<Aux>225127</Aux>
<ACHCode>Check2 1</ACHCode>
<ACHConverted RT/>
<ACHConvertedAc count/>
<IsElectronic>F ALSE</IsElectronic>
<IsOnUs>FALSE </IsOnUs>
<IsDeleted>FALS E</IsDeleted>
<IsInsert>FALSE </IsInsert>
<IsCorrected>FA LSE</IsCorrected>
<IsReject>FALSE </IsReject>
<RejectReason>0 </RejectReason>
<OutsortReason> 0</OutsortReason>
<Availability>0 </Availability>
<AppCode>0</AppCode>
<SPSelector>800 0</SPSelector>
<Currency>USD </Currency>
<AdjustmentType >0</AdjustmentType>
<AdjustmentReas on>0</AdjustmentReaso n>
<Images>
<Image>
<ImageView>Fron t</ImageView>
<ImageType>CCIT TG4</ImageType>
<ImageOffSet>46 1252</ImageOffSet>
<ImageLength>17 986</ImageLength>
</Image>
<Image>
<ImageView>Rear </ImageView>
<ImageType>CCIT TG4</ImageType>
<ImageOffSet>25 7889</ImageOffSet>
<ImageLength>84 32</ImageLength>
</Image>
</Images>
<CustomerUserIn fo>
<Field1>o225127 ot102000979t680 01764644391o</Field1>
<Field2>8000</Field2>
<Field3/>
<Field4>0011000 110000000000000 000</Field4>
</CustomerUserInf o>
</Item>
<Item>
<ISN>79010005 8 </ISN>
<ImageDocID>125 31</ImageDocID>
<Gender>DR</Gender>
<Amount>100.0 0</Amount>
<TC>1436</TC>
<AN>00496939561 6</AN>
<Fld4/>
<RT>122400724 </RT>
<RIC/>
<Aux/>
<ACHCode>Check2 1</ACHCode>
<ACHConverted RT/>
<ACHConvertedAc count/>
<IsElectronic>F ALSE</IsElectronic>
<IsOnUs>FALSE </IsOnUs>
<IsDeleted>TRUE </IsDeleted>
<IsInsert>FALSE </IsInsert>
<IsCorrected>FA LSE</IsCorrected>
<IsReject>FALSE </IsReject>
<RejectReason>0 </RejectReason>
<OutsortReason> 0</OutsortReason>
<Availability>0 </Availability>
<AppCode>0</AppCode>
<SPSelector>800 0</SPSelector>
<Currency>USD </Currency>
<AdjustmentType >0</AdjustmentType>
<AdjustmentReas on>0</AdjustmentReaso n>
<Images>
<Image>
<ImageView>Fron t</ImageView>
<ImageType>CCIT TG4</ImageType>
<ImageOffSet>47 9238</ImageOffSet>
<ImageLength>13 393</ImageLength>
</Image>
<Image>
<ImageView>Rear </ImageView>
<ImageType>CCIT TG4</ImageType>
<ImageOffSet>26 6321</ImageOffSet>
<ImageLength>28 24</ImageLength>
</Image>
</Images>
<CustomerUserIn fo>
<Field1>t122400 724t00496939561 6o1436</Field1>
<Field2>8000</Field2>
<Field3/>
<Field4>0011000 110000000000000 000</Field4>
</CustomerUserInf o>
</Item>
<Item>
<ISN>79010005 9 </ISN>
<ImageDocID>125 32</ImageDocID>
<Gender>CR</Gender>
<Amount>350000. 00</Amount>
<TC>009</TC>
<AN>010000014 0</AN>
<Fld4/>
<RT>031919186 </RT>
<RIC/>
<Aux>000035</Aux>
<ACHCode>Check2 1</ACHCode>
<ACHConverted RT/>
<ACHConvertedAc count/>
<IsElectronic>F ALSE</IsElectronic>
<IsOnUs>TRUE</IsOnUs>
<IsDeleted>FALS E</IsDeleted>
<IsInsert>FALSE </IsInsert>
<IsCorrected>FA LSE</IsCorrected>
<IsReject>FALSE </IsReject>
<RejectReason>0 </RejectReason>
<OutsortReason> 0</OutsortReason>
<Availability>0 </Availability>
<AppCode>0</AppCode>
<SPSelector>100 0</SPSelector>
<Currency>USD </Currency>
<AdjustmentType >0</AdjustmentType>
<AdjustmentReas on>0</AdjustmentReaso n>
<Images>
<Image>
<ImageView>Fron t</ImageView>
<ImageType>CCIT TG4</ImageType>
<ImageOffSet>49 2631</ImageOffSet>
<ImageLength>54 47</ImageLength>
</Image>
<Image>
<ImageView>Rear </ImageView>
<ImageType>CCIT TG4</ImageType>
<ImageOffSet>26 9145</ImageOffSet>
<ImageLength>30 26</ImageLength>
</Image>
</Images>
<CustomerUserIn fo>
<Field1>o000035 ot031919186t010 0000140o009</Field1>
<Field2>1001</Field2>
<Field3/>
<Field4>0011000 110000000000000 000</Field4>
</CustomerUserInf o>
</Item>
<Item>
<ISN>79010006 0 </ISN>
<ImageDocID>125 33</ImageDocID>
<Gender>DR</Gender>
<Amount>350000. 00</Amount>
<TC>500</TC>
<AN>139005009 8</AN>
<Fld4/>
<RT>5021-1000</RT>
<RIC/>
<Aux/>
<ACHCode>Check2 1</ACHCode>
<ACHConverted RT/>
<ACHConvertedAc count/>
<IsElectronic>F ALSE</IsElectronic>
<IsOnUs>TRUE</IsOnUs>
<IsDeleted>FALS E</IsDeleted>
<IsInsert>FALSE </IsInsert>
<IsCorrected>FA LSE</IsCorrected>
<IsReject>FALSE </IsReject>
<RejectReason>0 </RejectReason>
<OutsortReason> 0</OutsortReason>
<Availability>0 </Availability>
<AppCode>0</AppCode>
<SPSelector>200 0</SPSelector>
<Currency>USD </Currency>
<AdjustmentType >0</AdjustmentType>
<AdjustmentReas on>0</AdjustmentReaso n>
<Images>
<Image>
<ImageView>Fron t</ImageView>
<ImageType>CCIT TG4</ImageType>
<ImageOffSet>49 8078</ImageOffSet>
<ImageLength>61 15</ImageLength>
</Image>
<Image>
<ImageView>Rear </ImageView>
<ImageType>CCIT TG4</ImageType>
<ImageOffSet>27 2171</ImageOffSet>
<ImageLength>15 78</ImageLength>
</Image>
</Images>
<CustomerUserIn fo>
<Field1>t5021-1000t500</Field1>
<Field2>2006</Field2>
<Field3/>
<Field4/>
</CustomerUserInf o>
</Item>
<Item>
<ISN>79010006 1 </ISN>
<ImageDocID>125 34</ImageDocID>
<Gender>CR</Gender>
<Amount>1750.00 </Amount>
<TC>400</TC>
<AN>177001009 8</AN>
<Fld4/>
<RT>5020-1000</RT>
<RIC/>
<Aux/>
<ACHCode>Check2 1</ACHCode>
<ACHConverted RT/>
<ACHConvertedAc count/>
<IsElectronic>F ALSE</IsElectronic>
<IsOnUs>TRUE</IsOnUs>
<IsDeleted>FALS E</IsDeleted>
<IsInsert>FALSE </IsInsert>
<IsCorrected>FA LSE</IsCorrected>
<IsReject>FALSE </IsReject>
<RejectReason>0 </RejectReason>
<OutsortReason> 0</OutsortReason>
<Availability>0 </Availability>
<AppCode>0</AppCode>
<SPSelector>100 0</SPSelector>
<Currency>USD </Currency>
<AdjustmentType >0</AdjustmentType>
<AdjustmentReas on>0</AdjustmentReaso n>
<Images>
<Image>
<ImageView>Fron t</ImageView>
<ImageType>CCIT TG4</ImageType>
<ImageOffSet>50 4193</ImageOffSet>
<ImageLength>56 50</ImageLength>
</Image>
<Image>
<ImageView>Rear </ImageView>
<ImageType>CCIT TG4</ImageType>
<ImageOffSet>27 3749</ImageOffSet>
<ImageLength>29 63</ImageLength>
</Image>
</Images>
<CustomerUserIn fo>
<Field1>t5020-1000t400</Field1>
<Field2>1006</Field2>
<Field3/>
<Field4/>
</CustomerUserInf o>
</Item>
<Item>
<ISN>79010006 2 </ISN>
<ImageDocID>125 35</ImageDocID>
<Gender>DR</Gender>
<Amount>1750.00 </Amount>
<TC/>
<AN>20000125426 51</AN>
<Fld4/>
<RT>031000503 </RT>
<RIC/>
<Aux>017371</Aux>
<ACHCode>Check2 1</ACHCode>
<ACHConverted RT/>
<ACHConvertedAc count/>
<IsElectronic>F ALSE</IsElectronic>
<IsOnUs>FALSE </IsOnUs>
<IsDeleted>FALS E</IsDeleted>
<IsInsert>FALSE </IsInsert>
<IsCorrected>FA LSE</IsCorrected>
<IsReject>FALSE </IsReject>
<RejectReason>0 </RejectReason>
<OutsortReason> 0</OutsortReason>
<Availability>0 </Availability>
<AppCode>0</AppCode>
<SPSelector>800 0</SPSelector>
<Currency>USD </Currency>
<AdjustmentType >0</AdjustmentType>
<AdjustmentReas on>0</AdjustmentReaso n>
<Images>
<Image>
<ImageView>Fron t</ImageView>
<ImageType>CCIT TG4</ImageType>
<ImageOffSet>50 9843</ImageOffSet>
<ImageLength>10 988</ImageLength>
</Image>
<Image>
<ImageView>Rear </ImageView>
<ImageType>CCIT TG4</ImageType>
<ImageOffSet>27 6712</ImageOffSet>
<ImageLength>23 74</ImageLength>
</Image>
</Images>
<CustomerUserIn fo>
<Field1>o017371 ot031000503t200 0012542651o</Field1>
<Field2>8000</Field2>
<Field3/>
<Field4>0011000 110000000000000 000</Field4>
</CustomerUserInf o>
</Item>
<Item>
<ISN>79010006 3 </ISN>
<ImageDocID>125 36</ImageDocID>
<Gender>CR</Gender>
<Amount>60.00 </Amount>
<TC>600</TC>
<AN>100101000 1</AN>
<Fld4/>
<RT>5010-0000</RT>
<RIC/>
<Aux/>
<ACHCode>Check2 1</ACHCode>
<ACHConverted RT/>
<ACHConvertedAc count/>
<IsElectronic>F ALSE</IsElectronic>
<IsOnUs>TRUE</IsOnUs>
<IsDeleted>FALS E</IsDeleted>
<IsInsert>FALSE </IsInsert>
<IsCorrected>FA LSE</IsCorrected>
<IsReject>FALSE </IsReject>
<RejectReason>0 </RejectReason>
<OutsortReason> 0</OutsortReason>
<Availability>0 </Availability>
<AppCode>0</AppCode>
<SPSelector>100 0</SPSelector>
<Currency>USD </Currency>
<AdjustmentType >0</AdjustmentType>
<AdjustmentReas on>0</AdjustmentReaso n>
<Images>
<Image>
<ImageView>Fron t</ImageView>
<ImageType>CCIT TG4</ImageType>
<ImageOffSet>52 0831</ImageOffSet>
<ImageLength>26 54</ImageLength>
</Image>
<Image>
<ImageView>Rear </ImageView>
<ImageType>CCIT TG4</ImageType>
<ImageOffSet>27 9086</ImageOffSet>
<ImageLength>23 14</ImageLength>
</Image>
</Images>
<CustomerUserIn fo>
<Field1>t5010-0000t1001010001 o600</Field1>
<Field2>1006</Field2>
<Field3/>
<Field4/>
</CustomerUserInf o>
</Item>
<Item>
<ISN>79010006 4 </ISN>
<ImageDocID>125 37</ImageDocID>
<Gender>DR</Gender>
<Amount>60.00 </Amount>
<TC>046</TC>
<AN>012000010 4</AN>
<Fld4/>
<RT>5301-1000</RT>
<RIC/>
<Aux/>
<ACHCode>Check2 1</ACHCode>
<ACHConverted RT/>
<ACHConvertedAc count/>
<IsElectronic>F ALSE</IsElectronic>
<IsOnUs>TRUE</IsOnUs>
<IsDeleted>FALS E</IsDeleted>
<IsInsert>FALSE </IsInsert>
<IsCorrected>FA LSE</IsCorrected>
<IsReject>FALSE </IsReject>
<RejectReason>0 </RejectReason>
<OutsortReason> 0</OutsortReason>
<Availability>0 </Availability>
<AppCode>0</AppCode>
<SPSelector>200 0</SPSelector>
<Currency>USD </Currency>
<AdjustmentType >0</AdjustmentType>
<AdjustmentReas on>0</AdjustmentReaso n>
<Images>
<Image>
<ImageView>Fron t</ImageView>
<ImageType>CCIT TG4</ImageType>
<ImageOffSet>52 3485</ImageOffSet>
<ImageLength>38 94</ImageLength>
</Image>
<Image>
<ImageView>Rear </ImageView>
<ImageType>CCIT TG4</ImageType>
<ImageOffSet>28 1400</ImageOffSet>
<ImageLength>27 95</ImageLength>
</Image>
</Images>
<CustomerUserIn fo>
<Field1>t5301-1000t046</Field1>
<Field2>2001</Field2>
<Field3/>
<Field4/>
</CustomerUserInf o>
</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.xm l");
float batchTicketAmou nt = 0.0f;
bool batchTicketAmou ntStartElement = false;

while (reader.Read())
{
switch (reader.NodeTyp e)
{
case XmlNodeType.Ele ment: // The node is an element.
if (reader.Name == "BatchTktAmount ")
{
batchTicketAmou ntStartElement = true;
}
break;
case XmlNodeType.Tex t: //Display the text in each element.
if (batchTicketAmo untStartElement )
{
try
{
batchTicketAmou nt += float.Parse(rea der.Value);
}
catch (Exception ex)
{
System.Console. WriteLine(ex.Me ssage);
}
}
break;
case XmlNodeType.End Element: //Display the end of the element.
if (reader.Name == "BatchTktAmount ")
batchTicketAmou ntStartElement = false;
break;
}
}

Console.WriteLi ne(batchTicketA mount);
"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 "BatchTktAmount for
any <Batchelement s that may exist. There could be 1 or more...

As a verification, I may also want to add the <BATCH\Itemsele ments, 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>2008 0610:171706</StartTime>
<EndTime>200806 10:171747</EndTime>
<BusinessDate>2 0080610</BusinessDate>
<Device>26</Device>
<Site/>
<ProcType>Prime </ProcType>
<WorkTypeNumber >1</WorkTypeNumber>
<ClearingType>O utClearing</ClearingType>
<DebitsFirst>FA LSE</DebitsFirst>
<SortFamily>900 </SortFamily>
<Imaged>TRUE</Imaged>
<NbrOfBlocksInJ ob>1</NbrOfBlocksInJo b>
<CycleID>A</CycleID>
<Blocks>
<Block>
<BlkNbr>64</BlkNbr>
<BlkStartTime>2 0080610:171706</BlkStartTime>
<BlkEndTime>200 80610:171747</BlkEndTime>
<BlkSeqInJob> 1</BlkSeqInJob>
<BlkFrontImgFil eName>\\VMSERVE R1\MyApp\AllIte msExtract\G179B C\0064_5.fim</BlkFrontImgFile Name>
<BlkRearImgFile Name>\\VMSERVER 1\MyApp\AllItem sExtract\G179BC \0064_5.rim</BlkRearImgFileN ame>
<Batches>
<Batch>
<BatchNbr>1</BatchNbr>
<BranchData>
<BranchID>07901 0</BranchID>
<BranchDeviceID >79010</BranchDeviceID>
<BranchTill>0 </BranchTill>
<BranchBatchNbr >1</BranchBatchNbr>
<BranchBusiness Date>20080610</BranchBusinessD ate>
</BranchData>
<BatchTktAmount >617181.39</BatchTktAmount>
<BatchTktTC/>
<BatchTktAN/>
<BatchTktRT>444 444442</BatchTktRT>
<BatchTktAux/>
<Items>
<Item>
<ISN>79010000 3 </ISN>
<ImageDocID>124 78</ImageDocID>
<Gender>CR</Gender>
<Amount>17000.0 0</Amount>
<TC>009</TC>
<AN>012000015 3</AN>
<Fld4/>
<RT>5300-1000</RT>
<RIC/>
<Aux/>
<ACHCode>Check2 1</ACHCode>
<ACHConverted RT/>
<ACHConvertedAc count/>
<IsElectronic>F ALSE</IsElectronic>
<IsOnUs>TRUE</IsOnUs>
<IsDeleted>FALS E</IsDeleted>
<IsInsert>FALSE </IsInsert>
<IsCorrected>FA LSE</IsCorrected>
<IsReject>FALSE </IsReject>
<RejectReason>0 </RejectReason>
<OutsortReason> 0</OutsortReason>
<Availability>0 </Availability>
<AppCode>0</AppCode>
<SPSelector>100 0</SPSelector>
<Currency>USD </Currency>
<AdjustmentType >0</AdjustmentType>
<AdjustmentReas on>0</AdjustmentReaso n>
<Images>
<Image>
<ImageView>Fron t</ImageView>
<ImageType>CCIT TG4</ImageType>
<ImageOffSet>51 4</ImageOffSet>
<ImageLength>62 98</ImageLength>
</Image>
<Image>
<ImageView>Rear </ImageView>
<ImageType>CCIT TG4</ImageType>
<ImageOffSet>51 4</ImageOffSet>
<ImageLength>52 40</ImageLength>
</Image>
</Images>
<CustomerUserIn fo>
<Field1>t5300-1000t0120000153 o009</Field1>
<Field2>1001</Field2>
<Field3/>
<Field4/>
</CustomerUserInf o>
</Item>
<Item>
<ISN>79010000 4 </ISN>
<ImageDocID>124 79</ImageDocID>
<Gender>DR</Gender>
<Amount>17000.0 0</Amount>
<TC>1011</TC>
<AN>362343062 </AN>
<Fld4/>
<RT>999999999 </RT>
<RIC/>
<Aux/>
<ACHCode>Check2 1</ACHCode>
<ACHConverted RT/>
<ACHConvertedAc count/>
<IsElectronic>F ALSE</IsElectronic>
<IsOnUs>FALSE </IsOnUs>
<IsDeleted>FALS E</IsDeleted>
<IsInsert>FALSE </IsInsert>
<IsCorrected>FA LSE</IsCorrected>
<IsReject>FALSE </IsReject>
<RejectReason>0 </RejectReason>
<OutsortReason> 0</OutsortReason>
<Availability>0 </Availability>
<AppCode>0</AppCode>
<SPSelector>800 0</SPSelector>
<Currency>USD </Currency>
<AdjustmentType >0</AdjustmentType>
<AdjustmentReas on>0</AdjustmentReaso n>
<Images>
<Image>
<ImageView>Fron t</ImageView>
<ImageType>CCIT TG4</ImageType>
<ImageOffSet>68 12</ImageOffSet>
<ImageLength>76 24</ImageLength>
</Image>
<Image>
<ImageView>Rear </ImageView>
<ImageType>CCIT TG4</ImageType>
<ImageOffSet>57 54</ImageOffSet>
<ImageLength>28 20</ImageLength>
</Image>
</Images>
<CustomerUserIn fo>
<Field1>t031301 422t362343062o1 011</Field1>
<Field2>8000</Field2>
<Field3/>
<Field4>0011000 110000000000000 000</Field4>
</CustomerUserInf o>
</Item>
<Item>
<ISN>79010000 5 </ISN>
<ImageDocID>124 80</ImageDocID>
<Gender>CR</Gender>
<Amount>12405.1 8</Amount>
<TC>109</TC>
<AN>014002437 </AN>
<Fld4/>
<RT>5009-1000</RT>
<RIC/>
<Aux/>
<ACHCode>Check2 1</ACHCode>
<ACHConverted RT/>
<ACHConvertedAc count/>
<IsElectronic>F ALSE</IsElectronic>
<IsOnUs>TRUE</IsOnUs>
<IsDeleted>FALS E</IsDeleted>
<IsInsert>FALSE </IsInsert>
<IsCorrected>FA LSE</IsCorrected>
<IsReject>FALSE </IsReject>
<RejectReason>0 </RejectReason>
<OutsortReason> 0</OutsortReason>
<Availability>0 </Availability>
<AppCode>0</AppCode>
<SPSelector>100 0</SPSelector>
<Currency>USD </Currency>
<AdjustmentType >0</AdjustmentType>
<AdjustmentReas on>0</AdjustmentReaso n>
<Images>
<Image>
<ImageView>Fron t</ImageView>
<ImageType>CCIT TG4</ImageType>
<ImageOffSet>14 436</ImageOffSet>
<ImageLength>49 34</ImageLength>
</Image>
<Image>
<ImageView>Rear </ImageView>
<ImageType>CCIT TG4</ImageType>
<ImageOffSet>85 74</ImageOffSet>
<ImageLength>41 45</ImageLength>
</Image>
</Images>
<CustomerUserIn fo>
<Field1>t5009-1000t109</Field1>
<Field2>1003</Field2>
<Field3/>
<Field4/>
</CustomerUserInf o>
</Item>
<Item>
<ISN>79010000 6 </ISN>
<ImageDocID>124 81</ImageDocID>
<Gender>DR</Gender>
<Amount>1733.06 </Amount>
<TC/>
<AN>100241913 3</AN>
<Fld4/>
<RT>043301627 </RT>
<RIC/>
<Aux>0013866851 </Aux>
<ACHCode>Check2 1</ACHCode>
<ACHConverted RT/>
<ACHConvertedAc count/>
<IsElectronic>F ALSE</IsElectronic>
<IsOnUs>FALSE </IsOnUs>
<IsDeleted>FALS E</IsDeleted>
<IsInsert>FALSE </IsInsert>
<IsCorrected>FA LSE</IsCorrected>
<IsReject>FALSE </IsReject>
<RejectReason>0 </RejectReason>
<OutsortReason> 0</OutsortReason>
<Availability>0 </Availability>
<AppCode>0</AppCode>
<SPSelector>800 0</SPSelector>
<Currency>USD </Currency>
<AdjustmentType >0</AdjustmentType>
<AdjustmentReas on>0</AdjustmentReaso n>
<Images>
<Image>
<ImageView>Fron t</ImageView>
<ImageType>CCIT TG4</ImageType>
<ImageOffSet>19 370</ImageOffSet>
<ImageLength>10 443</ImageLength>
</Image>
<Image>
<ImageView>Rear </ImageView>
<ImageType>CCIT TG4</ImageType>
<ImageOffSet>12 719</ImageOffSet>
<ImageLength>51 43</ImageLength>
</Image>
</Images>
<CustomerUserIn fo>
<Field1>o001386 6851ot043301627 t1002419133o</Field1>
<Field2>8000</Field2>
<Field3/>
<Field4>0011000 110000000000000 000</Field4>
</CustomerUserInf o>
</Item>
<Item>
<ISN>79010000 7 </ISN>
<ImageDocID>124 82</ImageDocID>
<Gender>DR</Gender>
<Amount>10672.1 2</Amount>
<TC/>
<AN>009000091 </AN>
<Fld4/>
<RT>999999999 </RT>
<RIC/>
<Aux>1095468</Aux>
<ACHCode>Check2 1</ACHCode>
<ACHConverted RT/>
<ACHConvertedAc count/>
<IsElectronic>F ALSE</IsElectronic>
<IsOnUs>FALSE </IsOnUs>
<IsDeleted>FALS E</IsDeleted>
<IsInsert>FALSE </IsInsert>
<IsCorrected>FA LSE</IsCorrected>
<IsReject>FALSE </IsReject>
<RejectReason>0 </RejectReason>
<OutsortReason> 0</OutsortReason>
<Availability>0 </Availability>
<AppCode>0</AppCode>
<SPSelector>800 0</SPSelector>
<Currency>USD </Currency>
<AdjustmentType >0</AdjustmentType>
<AdjustmentReas on>0</AdjustmentReaso n>
<Images>
<Image>
<ImageView>Fron t</ImageView>
<ImageType>CCIT TG4</ImageType>
<ImageOffSet>29 813</ImageOffSet>
<ImageLength>22 934</ImageLength>
</Image>
<Image>
<ImageView>Rear </ImageView>
<ImageType>CCIT TG4</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****@discuss ions.microsoft. comwrote in message
news:6B******** *************** ***********@mic rosoft.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 <Batchelement s that may exist. There could be 1 or more...

As a verification, I may also want to add the <BATCH\Itemsele ments,
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>2008 0610:171706</StartTime>
<EndTime>200806 10:171747</EndTime>
<BusinessDate>2 0080610</BusinessDate>
<Device>26</Device>
<Site/>
<ProcType>Prime </ProcType>
<WorkTypeNumber >1</WorkTypeNumber>
<ClearingType>O utClearing</ClearingType>
<DebitsFirst>FA LSE</DebitsFirst>
<SortFamily>900 </SortFamily>
<Imaged>TRUE</Imaged>
<NbrOfBlocksInJ ob>1</NbrOfBlocksInJo b>
<CycleID>A</CycleID>
<Blocks>
<Block>
<BlkNbr>64</BlkNbr>
<BlkStartTime>2 0080610:171706</BlkStartTime>
<BlkEndTime>200 80610:171747</BlkEndTime>
<BlkSeqInJob> 1</BlkSeqInJob>
<BlkFrontImgFil eName>\\VMSERVE R1\MyApp\AllIte msExtract\G179B C\0064_5.fim</BlkFrontImgFile Name>
<BlkRearImgFile Name>\\VMSERVER 1\MyApp\AllItem sExtract\G179BC \0064_5.rim</BlkRearImgFileN ame>
<Batches>
<Batch>
<BatchNbr>1</BatchNbr>
<BranchData>
<BranchID>07901 0</BranchID>
<BranchDeviceID >79010</BranchDeviceID>
<BranchTill>0 </BranchTill>
<BranchBatchNbr >1</BranchBatchNbr>
<BranchBusiness Date>20080610</BranchBusinessD ate>
</BranchData>
<BatchTktAmount >617181.39</BatchTktAmount>
<BatchTktTC/>
<BatchTktAN/>
<BatchTktRT>444 444442</BatchTktRT>
<BatchTktAux/>
<Items>
<Item>
<ISN>79010000 3 </ISN>
<ImageDocID>124 78</ImageDocID>
<Gender>CR</Gender>
<Amount>17000.0 0</Amount>
<TC>009</TC>
<AN>012000015 3</AN>
<Fld4/>
<RT>5300-1000</RT>
<RIC/>
<Aux/>
<ACHCode>Check2 1</ACHCode>
<ACHConverted RT/>
<ACHConvertedAc count/>
<IsElectronic>F ALSE</IsElectronic>
<IsOnUs>TRUE</IsOnUs>
<IsDeleted>FALS E</IsDeleted>
<IsInsert>FALSE </IsInsert>
<IsCorrected>FA LSE</IsCorrected>
<IsReject>FALSE </IsReject>
<RejectReason>0 </RejectReason>
<OutsortReason> 0</OutsortReason>
<Availability>0 </Availability>
<AppCode>0</AppCode>
<SPSelector>100 0</SPSelector>
<Currency>USD </Currency>
<AdjustmentType >0</AdjustmentType>
<AdjustmentReas on>0</AdjustmentReaso n>
<Images>
<Image>
<ImageView>Fron t</ImageView>
<ImageType>CCIT TG4</ImageType>
<ImageOffSet>51 4</ImageOffSet>
<ImageLength>62 98</ImageLength>
</Image>
<Image>
<ImageView>Rear </ImageView>
<ImageType>CCIT TG4</ImageType>
<ImageOffSet>51 4</ImageOffSet>
<ImageLength>52 40</ImageLength>
</Image>
</Images>
<CustomerUserIn fo>
<Field1>t5300-1000t0120000153 o009</Field1>
<Field2>1001</Field2>
<Field3/>
<Field4/>
</CustomerUserInf o>
</Item>
<Item>
<ISN>79010000 4 </ISN>
<ImageDocID>124 79</ImageDocID>
<Gender>DR</Gender>
<Amount>17000.0 0</Amount>
<TC>1011</TC>
<AN>362343062 </AN>
<Fld4/>
<RT>999999999 </RT>
<RIC/>
<Aux/>
<ACHCode>Check2 1</ACHCode>
<ACHConverted RT/>
<ACHConvertedAc count/>
<IsElectronic>F ALSE</IsElectronic>
<IsOnUs>FALSE </IsOnUs>
<IsDeleted>FALS E</IsDeleted>
<IsInsert>FALSE </IsInsert>
<IsCorrected>FA LSE</IsCorrected>
<IsReject>FALSE </IsReject>
<RejectReason>0 </RejectReason>
<OutsortReason> 0</OutsortReason>
<Availability>0 </Availability>
<AppCode>0</AppCode>
<SPSelector>800 0</SPSelector>
<Currency>USD </Currency>
<AdjustmentType >0</AdjustmentType>
<AdjustmentReas on>0</AdjustmentReaso n>
<Images>
<Image>
<ImageView>Fron t</ImageView>
<ImageType>CCIT TG4</ImageType>
<ImageOffSet>68 12</ImageOffSet>
<ImageLength>76 24</ImageLength>
</Image>
<Image>
<ImageView>Rear </ImageView>
<ImageType>CCIT TG4</ImageType>
<ImageOffSet>57 54</ImageOffSet>
<ImageLength>28 20</ImageLength>
</Image>
</Images>
<CustomerUserIn fo>
<Field1>t031301 422t362343062o1 011</Field1>
<Field2>8000</Field2>
<Field3/>
<Field4>0011000 110000000000000 000</Field4>
</CustomerUserInf o>
</Item>
<Item>
<ISN>79010000 5 </ISN>
<ImageDocID>124 80</ImageDocID>
<Gender>CR</Gender>
<Amount>12405.1 8</Amount>
<TC>109</TC>
<AN>014002437 </AN>
<Fld4/>
<RT>5009-1000</RT>
<RIC/>
<Aux/>
<ACHCode>Check2 1</ACHCode>
<ACHConverted RT/>
<ACHConvertedAc count/>
<IsElectronic>F ALSE</IsElectronic>
<IsOnUs>TRUE</IsOnUs>
<IsDeleted>FALS E</IsDeleted>
<IsInsert>FALSE </IsInsert>
<IsCorrected>FA LSE</IsCorrected>
<IsReject>FALSE </IsReject>
<RejectReason>0 </RejectReason>
<OutsortReason> 0</OutsortReason>
<Availability>0 </Availability>
<AppCode>0</AppCode>
<SPSelector>100 0</SPSelector>
<Currency>USD </Currency>
<AdjustmentType >0</AdjustmentType>
<AdjustmentReas on>0</AdjustmentReaso n>
<Images>
<Image>
<ImageView>Fron t</ImageView>
<ImageType>CCIT TG4</ImageType>
<ImageOffSet>14 436</ImageOffSet>
<ImageLength>49 34</ImageLength>
</Image>
<Image>
<ImageView>Rear </ImageView>
<ImageType>CCIT TG4</ImageType>
<ImageOffSet>85 74</ImageOffSet>
<ImageLength>41 45</ImageLength>
</Image>
</Images>
<CustomerUserIn fo>
<Field1>t5009-1000t109</Field1>
<Field2>1003</Field2>
<Field3/>
<Field4/>
</CustomerUserInf o>
</Item>
<Item>
<ISN>79010000 6 </ISN>
<ImageDocID>124 81</ImageDocID>
<Gender>DR</Gender>
<Amount>1733.06 </Amount>
<TC/>
<AN>100241913 3</AN>
<Fld4/>
<RT>043301627 </RT>
<RIC/>
<Aux>0013866851 </Aux>
<ACHCode>Check2 1</ACHCode>
<ACHConverted RT/>
<ACHConvertedAc count/>
<IsElectronic>F ALSE</IsElectronic>
<IsOnUs>FALSE </IsOnUs>
<IsDeleted>FALS E</IsDeleted>
<IsInsert>FALSE </IsInsert>
<IsCorrected>FA LSE</IsCorrected>
<IsReject>FALSE </IsReject>
<RejectReason>0 </RejectReason>
<OutsortReason> 0</OutsortReason>
<Availability>0 </Availability>
<AppCode>0</AppCode>
<SPSelector>800 0</SPSelector>
<Currency>USD </Currency>
<AdjustmentType >0</AdjustmentType>
<AdjustmentReas on>0</AdjustmentReaso n>
<Images>
<Image>
<ImageView>Fron t</ImageView>
<ImageType>CCIT TG4</ImageType>
<ImageOffSet>19 370</ImageOffSet>
<ImageLength>10 443</ImageLength>
</Image>
<Image>
<ImageView>Rear </ImageView>
<ImageType>CCIT TG4</ImageType>
<ImageOffSet>12 719</ImageOffSet>
<ImageLength>51 43</ImageLength>
</Image>
</Images>
<CustomerUserIn fo>
<Field1>o001386 6851ot043301627 t1002419133o</Field1>
<Field2>8000</Field2>
<Field3/>
<Field4>0011000 110000000000000 000</Field4>
</CustomerUserInf o>
</Item>
<Item>
<ISN>79010000 7 </ISN>
<ImageDocID>124 82</ImageDocID>
<Gender>DR</Gender>
<Amount>10672.1 2</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 batchTicketAmou nt = 0.0d;

XDocument loaded = XDocument.Load( "FileExchange.x ml");
var q = (from b in loaded.Descenda nts("Batch")
select (double)b.Eleme nt("BatchTktAmo unt")).Sum(rec =rec);
batchTicketAmou nt = (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.SelectSin gleNode("./BatchNbr");
XmlNode Amount =
batch.SelectSin gleNode("./BatchTktAmount" );

Console.WriteLi ne("######Batch Nbr:{0},
BatchTktAmount: {1}#######",
Nbr.InnerText, Amount.InnerTex t);

//query items of the batch
Console.WriteLi ne("\tItems:") ;
XmlNodeList items = batch.SelectNod es("./Items/Item");

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

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

}

}

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

Also, I saw that in Tim's new reply, he mentioned the X-LINQ
feature(provide d 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****@microsof t.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****@discuss ions.microsoft. com>
References: <6B************ *************** *******@microso ft.com>
<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****@discuss ions.microsoft. comwrote in message
news:6B******* *************** ************@mi crosoft.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 <Batchelement s that may exist. There could be 1 or more...

As a verification, I may also want to add the <BATCH\Itemsele ments,
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****@microsof t.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.SelectSin gleNode("./BatchNbr");
XmlNode Amount =
batch.SelectSi ngleNode("./BatchTktAmount" );

Console.WriteLi ne("######Batch Nbr:{0},
BatchTktAmount :{1}#######",
Nbr.InnerText, Amount.InnerTex t);

//query items of the batch
Console.WriteLi ne("\tItems:") ;
XmlNodeList items = batch.SelectNod es("./Items/Item");

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

Console.WriteLi ne("\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
"BatchTktAmoun t>
>for
any <Batchelement s that may exist. There could be 1 or more...

As a verification, I may also want to add the <BATCH\Itemsele ments,
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2388
by: chuck amadi | last post by:
By the way list is there a better way than using the readlines() to > > >parse the mail data into a file , because Im using > > >email.message_from_file it returns > > >all the data i.e reads one entire line from the file , headers as well > > >as just the desired body messages . > > > > > >fp = file("/home/chuck/pythonScript/testbox") > >...
22
872
by: Ram Laxman | last post by:
Hi all, I have a text file which have data in CSV format. "empno","phonenumber","wardnumber" 12345,2234353,1000202 12326,2243653,1000098 Iam a beginner of C/C++ programming. I don't know how to tokenize the comma separated values.I used strtok function reading line by line using fgets.but it gives some weird behavior.It doesnot stripout...
3
2642
by: slylos | last post by:
I've got a section of code in my app that keeps track of how much time an employee has accrued, which equals out to 1.33 days of PTO per month. I'm trying to store the time accrued so far in an XML file. I have no problems writing to and reading from the XML file and all my values are correct. The problem I'm having is my calculation never...
6
8545
by: trevor | last post by:
Incorrect values when using float.Parse(string) I have discovered a problem with float.Parse(string) not getting values exactly correct in some circumstances(CSV file source) but in very similar circumstances(XML file source) and with exactly the same value it gets it perfectly correct all the time. These are the results I got, XML is...
5
64603
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 article “How to Parse a File in C++”, we are actually mostly lexing a file which is the breaking down of a stream in to its component parts,...
1
64039
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 article “How to Parse a File in C++”, we are actually mostly lexing a file which is the breaking down of a stream in to its component parts,...
11
3508
by: Peter Pei | last post by:
One bad design about elementtree is that it has different ways parsing a string and a file, even worse they return different objects: 1) When you parse a file, you can simply call parse, which returns a elementtree, on which you can then apply xpath; 2) To parse a string (xml section), you can call XML or fromstring, but both return element...
2
3210
by: Lawrence Krubner | last post by:
Imagine a template system that works by getting a file, as a string, and then putting it through eval(), something like this: $formAsString = $controller->command("readFileAndReturnString", $formName); // 06-22-07 - the next commands try to import all the functions that the
5
2696
by: goldtech | last post by:
SAX XML Parse Python error message Hi, My first attempt at SAX, but have an error message I need help with. I cite the error message, code, and xml below. Be grateful if anyone can tell me what the fix is. Thanks.
0
7639
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8074
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7608
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7926
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6198
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5465
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3613
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3594
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1172
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.