Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Instructions
● Please thoroughly read the test before beginning
● We expect the test to be completed using C#
● Google may be used.
● We have included a DebitOrders.xml.txt input file. Please rename this to
DebitOrders.xml (by removing the.txt). This is the file that you must read your data
from.
● We have included a SampleOutput.txt file. This is only to give you an idea of what the
output could possible look like.
● Please provide a zipped (.zip) file of the source code (no binaries) and the resulting
output files for your application.
● Your application should be stable and should always exit gracefully
Summary
Read the data from the provided XML file (DebitOrders.xml) into flat files to be submitted to
the banks. A file for each bank should be created, so all the records for the same bank will
be in the same output file. The output files will contain details for every debit order to be
processed for that bank, as well as some header/summary data describing and counting all
the detail records.
Input File (DebitOrders.xml)
The xml file contains multiple records, each with the following nodes:
Element Description
<accountholder> First name and Surname of the account
holder
<accountnumber> Account number that needs to be debited
<accounttype> Type of account that needs to be debited
<bankname> Bank where the account is held
<branch> Branch where the account is held
<amount> Amount that needs to be debited, in rand
and cent
<date> Date that debit needs to happen
(mm/dd/yyyy)
Output File
File Name
The output file should be the full bank name, with a .txt extension.
File Header Record
Every file will have a single header record line at the top that summarizes the data in the file.
If we take the example of Beep Bank with 100 records to the value of R90998.10, the header
record will have the following data in one long string:
BEEP BANK 1000009099810
Element Description Pad char Pad side Length
Bank
name
First 16 characters of the Bank
name as per file name, padded
with spaces at the end if the
name is less than 16 characters
long. Convert to Uppercase.
[space] right 16
Record
count
Number of data records in the
file, depicted as a 3 character,
zero-left-padded string.
0 left 3
Total
value
Value (in cents) of all amounts in
the file, depicted as a 10
character, zero-left-padded
string.
0 left 10
Total Header Record Length 29
Detail Record Formatting
Every deduction that belongs to a bank will be written to that bank’s file, one per line. Each
detail record will be the same length. A detailed record example is explained here: If we take
the example of a deduction of R100.72 on 31 December 2012 from Maria Smith’s Credit
Card , account number 123456 for the branch in Durban , the detail record in the output file
will be represented as the following:
MSmith 123456 CC Durban 0010072 31201212
Element Description Pad char Pad side Length
Initials First initial of account holder,
depicted as a single character.
N/A N/A 1
Surname Surname (spaces removed) of the
account holder depicted as a 15
character, space-right-padded
string.
All spaces to be removed from
surnames like "Le Roux" before
padding.
[space] right 15
AccountNo Account number to be debited,
depicted as a 14 character,
space-right-padded string.
[space] right 14
Account
Type
A mnemonic/abbreviation for the
account type depicted as a 3
character, space-right-padded
string using these lookups:
● CH = Cheque account
● SAV = Savings account
● CR = Credit card
● OTH = Any other account
type
[space] right 3
Branch Branch name where account is
held, depicted as a 10 character,
space-right-padded string
[space] right 10
Amount Amount, in cents, to be deducted
from account, depicted as a 7
character, zero-left-padded string.
0 left 7
Date Debit date depicted as a 8
character string representing the
date in the format ddyyyymm
N/A N/A 8
Total Detail Record Length 58
Detail Record Sorting
All detail records must be sorted in ascending order based on the amount, and then in
ascending order based on the Account Holder’s surname. So where two records of the same
amount is found, these records must be sorted based on the surname of the account holder.
File Ending
The file should end with a CRLF (carriage return line feed) after the final record.
Optional items
● Create a detail record class that can be populated from the file, and used to write the
formatted string to the output file.
● Give the user progress feedback while processing the file.
● Give a summary of the files produced with values and counts
----DebitOrder.xml--------------------

<pre><debitorders>
  <deduction>
    <accountholder>Georgina Sinclair</accountholder>
	<accountnumber>408999703657</accountnumber>
	<accounttype>cheque</accounttype>
	<bankname>First National Bank</bankname>
	<branch>Fourways</branch>
	<amount>275.00</amount>
	<date>12/01/2012</date>
  </deduction>
  <deduction>
    <accountholder>Zachary Whitehead</accountholder>
	<accountnumber>409122372301</accountnumber>
	<accounttype>cheque</accounttype>
	<bankname>ABSA</bankname>
	<branch>Irene</branch>
	<amount>70.25</amount>
	<date>12/01/2012</date>
  </deduction>
  <deduction>
    <accountholder>Toby Henderson</accountholder>
	<accountnumber>401255489873</accountnumber>
	<accounttype>cheque</accounttype>
	<bankname>First National Bank</bankname>
	<branch>Edenvale</branch>
	<amount>181.03</amount>
	<date>12/13/2012</date>
  </deduction>
  <deduction>
    <accountholder>Katherine Cooke</accountholder>
	<accountnumber>409155874935</accountnumber>
	<accounttype>savings</accounttype>
	<bankname>ABSA</bankname>
	<branch>Southdowns</branch>
	<amount>975.89</amount>
	<date>01/01/2013</date>
  </deduction>
  <deduction>
    <accountholder>Bradley James</accountholder>
	<accountnumber>409254998</accountnumber>
	<accounttype>savings</accounttype>
	<bankname>ABSA</bankname>
	<branch>Melville</branch>
	<amount>207.74</amount>
	<date>12/09/2012</date>
  </deduction>
  <deduction>
    <accountholder>Sophie Lane</accountholder>
	<accountnumber>409771987</accountnumber>
	<accounttype>savings</accounttype>
	<bankname>ABSA</bankname>
	<branch>Roodepoort</branch>
	<amount>207.74</amount>
	<date>12/31/2012</date>
  </deduction>
</debitorders>




--- output--------

First National B0020000045603
GSinclair 408999703657 CH Fourways 002750001122012
THenderson 401255489873 CH Edenvale 001810313122012

ABSA 0040000146162
ZWhitehead 409122372301 CH Irene 000702501122012
KCooke 409155874935 SAVSouthdowns009758901012013
BJames 409254998 SAVMelville 002077409122012
SLane 409771987 SAVRoodepoort002077431122012

What I have tried:

C#

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;

namespace DebitOrders
{
    class Program
    {
       

  
        static void Main(string[] args)
        {
            string onlyContent = string.Empty;

            XmlDocument xdoc = new XmlDocument();
            xdoc.Load(@"C:\zms\DebitOrders\DebitOrders\DebitOrders.xml");

            var debitorders = xdoc.SelectNodes("debitorders/deduction");
            for (int i = 0; i < debitorders.Count; i++)
            {
                //onlyContent += string.Format("\n bankname", i);
                onlyContent += string.Format("\n{0}:", i);
                foreach (XmlNode node in debitorders[i].ChildNodes)
                    onlyContent += string.Format("{0},", node.InnerText);
            }


            File.WriteAllText(@"C:\zms\DebitOrders\DebitOrders\DebitOrders.txt", onlyContent);

        }
        }
      }
  
//string path=Server.MapPath("~/service/AppValues.xml");

//XDocument document = XDocument.Load(path);
Posted
Updated 7-Apr-17 1:46am
v2
Comments
CHill60 6-Apr-17 9:54am    
And what is wrong with the code that you have tried?
[no name] 6-Apr-17 10:05am    
And what is it that you expect us to tell you?
We don't have your files.
We can't see your screen.
We can't see your output file.
It's not our test.
Patrice T 6-Apr-17 18:09pm    
And there is something wrong in your code ? a problem ?
Patrice T 7-Apr-17 7:33am    
What you want IS NOT a PROBLEM.

1 solution

please call method shown below , hope it works thank you

static public string XMLRead()
    {
        string onlyContent = "";
        DataSet ds = new DataSet();
        string Strpath = @"C:\zms\DebitOrders\DebitOrders";
        try
        {
            ds.ReadXml(Strpath + "\\DebitOrders.xml");
            if (ds.Tables.Count != 0)
            {
                DataTable dtXml = ds.Tables[0];

                foreach (DataRow dr in dtXml.Rows)
                {
                    onlyContent += dr[0].ToString();
                }
            }
        }
        catch
        {
            return Environment.MachineName;
        }
        return onlyContent;
    }
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900