tags:

views:

35

answers:

2

Hi Guys,

I am working on an application, in which i will be receiving data in HashMap. Every "value" in hasmap needs to be formatted based on XML Key tables. For example-

suppose HashMap has following values-

TxnDate = "15-Oct-2010"
cardType = "MC"

The XML table is something like this-

<Param name="TxnDate" input="dd-Mon-yyyy" output="dd/mm/yyyy" />
<Param name="cardType" input="MC" output="MASTERCARD" />

for everything else I can do a direct mapping, but for date i need to format the data. I am so confuse which approach shall i follow?

Can anyone guide me in a proper direction...I am writing the application in JAVA.

A: 

Does the XML change during runtime? If its fairly static you could have an input and output map keyed by the name attribute and populate these maps with the XML config data. Looking up the input/output format would then be simple.

Note that this would only work for unique name attributes. For cardType I suspect this wouldn't be the case.

Qwerky
+2  A: 

You will have to write a converter from one set of date type to another. This could be done in the code which reads the XML for further processing. The following code converts one form of date to another

public static void main(String[] args) throws ParseException
    {
        String date = "15-Oct-2010";
        SimpleDateFormat sdf1 = new SimpleDateFormat("dd-MMM-yyyy");
        SimpleDateFormat sdf2 = new SimpleDateFormat("dd/MM/yyyy");
        System.out.println(sdf2.format(sdf1.parse(date)));
    }
Gaurav Saxena