In the below Java Code for handling xml elements i am using multiple if-else condition. What is the better way to avoid these if-else conditions where I have used "A" and "B" for condition check.
My Code :
...
if(((Element)nodeValue).hasAttribute("name")) {
String nVal = ((Element)nodeValue).getAttribute("name");
if(nVal.equals("A")) {
rNodeContent = nodeValue.getTextContent();
... Processing...
} else if(nVal.equals("B")) {
rNodeContent = nodeValue.getTextContent();
... Processing...
}
}
...
nVal, you might want to create a method that acceptsnValand process it there but if you useif elseinside the method, it won't help either, it really depends on what you want to do with it.ifs can be combined using&&