Skip to content
Advertisement

Comparing XML in java

Here are two XMLs , I am trying to compare and put the respective data in excel sheet.

I have a multidimensional array called provisions.

JavaScript

AND

JavaScript

Now this XML data is for 2 plans and my provisions array contains

provisions == [[Plan Features,,][Deductible,,][Individual,,]…..]

This is what I have done

JavaScript

The problem happens when that extra node of Family Out-of-network comes into picture. This is my final array is

JavaScript

I want to get right values into corresponding array element.

More code can be seen here pastie.org/1308625

Advertisement

Answer

Don’t use an array.

Use: Map<String, Map<String, String>>

so that:

  • the first String (key to the outer map) is the feature name (e.g. “Life Time Maximum”)
  • the second String (key to the inner map) is the plan name (there don’t seem to be any actual plan names in your XML documents so “Plan1” and “Plan2” could suffice)
  • the third String (value to the inner map) should be the value for that particular feature in that particular plan (e.g. “Unlimited” for “Life Time Maximum” in “Plan1”)

You could have:

JavaScript

as, unlike an array, the number of entries for each feature doesn’t have to be fixed (different features can have different numbers of entries)

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement