Link to home
Start Free TrialLog in
Avatar of zimmer9
zimmer9Flag for United States of America

asked on

How would you revise the following C# code to capture BOTH the Root Descendents of "postInfo" plus the value of "imageRefKey" for each iteration?

I am working with a C# application using .Net Framework 4.0 and VS2010.
In this application, I read the XML file shown below.
The application currently pulls in the root descendents of "postInfo" (date, RT, accountNumber, seqNum, trancode, amount and serialNumber).

How would you revise the following C# code to capture BOTH the Root Descendents of "postInfo" and in addition, the value of "imageRefKey" for each iteration?

 <postingInfo>
           <date></date>
           <RT></RT>
           <accountNumber></accountNumber>
           <seqNum></seqNum>
           <trancode></trancode>
           <amount></amount>
           <serialNumber></serialNumber>
 </postingInfo>

 <imageRefKey>201606220_F.TIF</imageRefKey>       <--- 1 additional element  *********

-----------------------------

using System.Xml.Linq;

XDocument xdoc = XDocument.Load(filePath);

var postingInfo = (from pi in xdoc.Root.Descendants("postingInfo")
                   select new
                   {
                       Date = pi.Element("date").Value,
                       RT = pi.Element("RT").Value,
                       AccountNo = pi.Element("accountNumber").Value,
                       SeqNum = pi.Element("seqNum").Value,
                       Trancode = pi.Element("trancode").Value,
                       Amount = pi.Element("amount").Value,
                       SerialNo = pi.Element("serialNumber").Value
                   }).ToList();

foreach (var data in postingInfo)
{
    Console.WriteLine("Date : {0}  RT : {1}  AccountNo : {2}  SeqNum : {3}  Trancode : {4}  Amount : {5}  SerialNum : {6}",
      data.Date, data.RT, data.AccountNo, data.SeqNum, data.Trancode, data.Amount, data.SerialNo);
}

---------------------------------------------------------            

 The XML file format I use is as follows:

 <?xml version="1.0" encoding="UTF-8"?>

 <bdiData>
   <documentControlInfo>
     <documentInfo>
       <docDescription></docDescription>
       <docID>
         <ID></ID>
       </docID>
       <docModifier></docModifier>
       <docCreateDate></docCreateDate>
       <docCreateTime></docCreateTime>
       <standardVersion></standardVersion>
       <testIndicator></testIndicator>
       <resendIndicator></resendIndicator>
     </documentInfo>
     <sourceInfo>
       <sourceName></sourceName>
       <sourceID>
         <idOther></idOther>
       </sourceID>
     </sourceInfo>
     <destinationInfo>
       <destinationName></destinationName>
       <destinationID>
         <idOther></idOther>
       </destinationID>
     </destinationInfo>
   </documentControlInfo>
   <checkItemCollection>
     <collectionInfo>
       <description></description>
       <ID></ID>
       <Classification>
         <classification></classification>
       </Classification>
     </collectionInfo>
     <checkItemBatch>
       <checkItemBatchInfo>
         <description></description>
         <ID></ID>
         <Classification>
           <classification></classification>
         </Classification>
       </checkItemBatchInfo>
       <checkItem>
         <checkItemType></checkItemType>
         <checkAmount></checkAmount>
         <postingInfo>                                          <---Root element begin
           <date></date>
           <RT></RT>
           <accountNumber></accountNumber>
           <seqNum></seqNum>
           <trancode></trancode>
           <amount></amount>
           <serialNumber></serialNumber>
         </postingInfo>                                         <---Root element end
         <totalImageViewsDelivered></totalImageViewsDelivered>
         <imageView>
           <imageIndicator></imageIndicator>
           <imageViewInfo>
             <Format>
               <Baseline></Baseline>
             </Format>
             <Compression>
               <Baseline></Baseline>
             </Compression>
             <ViewSide></ViewSide>
             <imageViewLocator>
               <imageRefKey></imageRefKey>
               <imageFileLocator></imageFileLocator>
             </imageViewLocator>
           </imageViewInfo>
           <imageViewInfo>
             <Format>
               <Baseline></Baseline>
             </Format>
             <Compression>
               <Baseline></Baseline>
             </Compression>
             <ViewSide></ViewSide>
             <imageViewLocator>
               <imageRefKey>201606220_F.TIF</imageRefKey>       <--- 1 additional element  *********
               <imageFileLocator></imageFileLocator>
             </imageViewLocator>
           </imageViewInfo>
         </imageView>
       </checkItem>      
       <checkItemBatchSummary>
         <totalItemCount></totalItemCount>
         <totalBatchAmount></totalBatchAmount>
         <totalBatchImageViewsDelivered></totalBatchImageViewsDelivered>
       </checkItemBatchSummary>
     </checkItemBatch>
     <collectionSummary>
       <totalBatchCount></totalBatchCount>
       <totalItemCount></totalItemCount>
       <totalCollectionAmount></totalCollectionAmount>
       <totalCollectionImageViewsDelivered></totalCollectionImageViewsDelivered>
     </collectionSummary>
   </checkItemCollection>
   <documentSummaryInfo>
     <totalCollectionCount></totalCollectionCount>
     <totalBatchCount></totalBatchCount>
     <totalItemCount></totalItemCount>
     <totalDocumentAmount></totalDocumentAmount>
     <totalDocumentImageViewsDelivered></totalDocumentImageViewsDelivered>
   </documentSummaryInfo>
 </bdiData>
ASKER CERTIFIED SOLUTION
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial