zimmer9
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></accountNu mber>
<seqNum></seqNum>
<trancode></trancode>
<amount></amount>
<serialNumber></serialNumb er>
</postingInfo>
<imageRefKey>201606220_F.T IF</imageR efKey> <--- 1 additional element *********
-------------------------- ---
using System.Xml.Linq;
XDocument xdoc = XDocument.Load(filePath);
var postingInfo = (from pi in xdoc.Root.Descendants("pos tingInfo")
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").Val ue,
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></docDescr iption>
<docID>
<ID></ID>
</docID>
<docModifier></docModifier >
<docCreateDate></docCreate Date>
<docCreateTime></docCreate Time>
<standardVersion></standar dVersion>
<testIndicator></testIndic ator>
<resendIndicator></resendI ndicator>
</documentInfo>
<sourceInfo>
<sourceName></sourceName>
<sourceID>
<idOther></idOther>
</sourceID>
</sourceInfo>
<destinationInfo>
<destinationName></destina tionName>
<destinationID>
<idOther></idOther>
</destinationID>
</destinationInfo>
</documentControlInfo>
<checkItemCollection>
<collectionInfo>
<description></description >
<ID></ID>
<Classification>
<classification></classifi cation>
</Classification>
</collectionInfo>
<checkItemBatch>
<checkItemBatchInfo>
<description></description >
<ID></ID>
<Classification>
<classification></classifi cation>
</Classification>
</checkItemBatchInfo>
<checkItem>
<checkItemType></checkItem Type>
<checkAmount></checkAmount >
<postingInfo> <---Root element begin
<date></date>
<RT></RT>
<accountNumber></accountNu mber>
<seqNum></seqNum>
<trancode></trancode>
<amount></amount>
<serialNumber></serialNumb er>
</postingInfo> <---Root element end
<totalImageViewsDelivered> </totalIma geViewsDel ivered>
<imageView>
<imageIndicator></imageInd icator>
<imageViewInfo>
<Format>
<Baseline></Baseline>
</Format>
<Compression>
<Baseline></Baseline>
</Compression>
<ViewSide></ViewSide>
<imageViewLocator>
<imageRefKey></imageRefKey >
<imageFileLocator></imageF ileLocator >
</imageViewLocator>
</imageViewInfo>
<imageViewInfo>
<Format>
<Baseline></Baseline>
</Format>
<Compression>
<Baseline></Baseline>
</Compression>
<ViewSide></ViewSide>
<imageViewLocator>
<imageRefKey>201606220_F.T IF</imageR efKey> <--- 1 additional element *********
<imageFileLocator></imageF ileLocator >
</imageViewLocator>
</imageViewInfo>
</imageView>
</checkItem>
<checkItemBatchSummary>
<totalItemCount></totalIte mCount>
<totalBatchAmount></totalB atchAmount >
<totalBatchImageViewsDeliv ered></tot alBatchIma geViewsDel ivered>
</checkItemBatchSummary>
</checkItemBatch>
<collectionSummary>
<totalBatchCount></totalBa tchCount>
<totalItemCount></totalIte mCount>
<totalCollectionAmount></t otalCollec tionAmount >
<totalCollectionImageViews Delivered> </totalCol lectionIma geViewsDel ivered>
</collectionSummary>
</checkItemCollection>
<documentSummaryInfo>
<totalCollectionCount></to talCollect ionCount>
<totalBatchCount></totalBa tchCount>
<totalItemCount></totalIte mCount>
<totalDocumentAmount></tot alDocument Amount>
<totalDocumentImageViewsDe livered></ totalDocum entImageVi ewsDeliver ed>
</documentSummaryInfo>
</bdiData>
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></accountNu
<seqNum></seqNum>
<trancode></trancode>
<amount></amount>
<serialNumber></serialNumb
</postingInfo>
<imageRefKey>201606220_F.T
--------------------------
using System.Xml.Linq;
XDocument xdoc = XDocument.Load(filePath);
var postingInfo = (from pi in xdoc.Root.Descendants("pos
select new
{
Date = pi.Element("date").Value,
RT = pi.Element("RT").Value,
AccountNo = pi.Element("accountNumber"
SeqNum = pi.Element("seqNum").Value
Trancode = pi.Element("trancode").Val
Amount = pi.Element("amount").Value
SerialNo = pi.Element("serialNumber")
}).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></docDescr
<docID>
<ID></ID>
</docID>
<docModifier></docModifier
<docCreateDate></docCreate
<docCreateTime></docCreate
<standardVersion></standar
<testIndicator></testIndic
<resendIndicator></resendI
</documentInfo>
<sourceInfo>
<sourceName></sourceName>
<sourceID>
<idOther></idOther>
</sourceID>
</sourceInfo>
<destinationInfo>
<destinationName></destina
<destinationID>
<idOther></idOther>
</destinationID>
</destinationInfo>
</documentControlInfo>
<checkItemCollection>
<collectionInfo>
<description></description
<ID></ID>
<Classification>
<classification></classifi
</Classification>
</collectionInfo>
<checkItemBatch>
<checkItemBatchInfo>
<description></description
<ID></ID>
<Classification>
<classification></classifi
</Classification>
</checkItemBatchInfo>
<checkItem>
<checkItemType></checkItem
<checkAmount></checkAmount
<postingInfo> <---Root element begin
<date></date>
<RT></RT>
<accountNumber></accountNu
<seqNum></seqNum>
<trancode></trancode>
<amount></amount>
<serialNumber></serialNumb
</postingInfo> <---Root element end
<totalImageViewsDelivered>
<imageView>
<imageIndicator></imageInd
<imageViewInfo>
<Format>
<Baseline></Baseline>
</Format>
<Compression>
<Baseline></Baseline>
</Compression>
<ViewSide></ViewSide>
<imageViewLocator>
<imageRefKey></imageRefKey
<imageFileLocator></imageF
</imageViewLocator>
</imageViewInfo>
<imageViewInfo>
<Format>
<Baseline></Baseline>
</Format>
<Compression>
<Baseline></Baseline>
</Compression>
<ViewSide></ViewSide>
<imageViewLocator>
<imageRefKey>201606220_F.T
<imageFileLocator></imageF
</imageViewLocator>
</imageViewInfo>
</imageView>
</checkItem>
<checkItemBatchSummary>
<totalItemCount></totalIte
<totalBatchAmount></totalB
<totalBatchImageViewsDeliv
</checkItemBatchSummary>
</checkItemBatch>
<collectionSummary>
<totalBatchCount></totalBa
<totalItemCount></totalIte
<totalCollectionAmount></t
<totalCollectionImageViews
</collectionSummary>
</checkItemCollection>
<documentSummaryInfo>
<totalCollectionCount></to
<totalBatchCount></totalBa
<totalItemCount></totalIte
<totalDocumentAmount></tot
<totalDocumentImageViewsDe
</documentSummaryInfo>
</bdiData>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.