• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help Needed in XML!!

 
Rajesh Rajaram
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear All,

I have a XML file as below. when i parse it i am getting only the first element value for all the 21 nodes.

<?xml version="1.0" encoding="UTF-8"?>

<RoHSExemptionCheckbox>
<RoHSExemption>1</RoHSExemption>
<RoHSExemption>2a</RoHSExemption>
<RoHSExemption>2b</RoHSExemption>
<RoHSExemption>2c</RoHSExemption>
<RoHSExemption>3</RoHSExemption>
<RoHSExemption>4</RoHSExemption>
<RoHSExemption>5</RoHSExemption>
<RoHSExemption>0</RoHSExemption>
<RoHSExemption>0</RoHSExemption>
<RoHSExemption>0</RoHSExemption>
<RoHSExemption>0</RoHSExemption>
<RoHSExemption>0</RoHSExemption>
<RoHSExemption>0</RoHSExemption>
<RoHSExemption>0</RoHSExemption>
<RoHSExemption>0</RoHSExemption>
<RoHSExemption>0</RoHSExemption>
<RoHSExemption>0</RoHSExemption>
<RoHSExemption>0</RoHSExemption>
<RoHSExemption>0</RoHSExemption>
<RoHSExemption>0</RoHSExemption>
<RoHSExemption>0</RoHSExemption>
</RoHSExemptionCheckbox>

I am using this java code.

String sRoHSDeclaration = getStringValueFromLevelOneTag(firstDBTagElement,"RoHSDeclaration");
String sSupplierAcceptance = getStringValueFromLevelOneTag(firstDBTagElement,"SupplierAcceptance");
String sRoHSExemption1 = getStringValueFromLevelOneTag(firstDBTagElement,"RoHSExemption");
String sRoHSExemption2 = getStringValueFromLevelOneTag(firstDBTagElement,"RoHSExemption");
String sRoHSExemption3 = getStringValueFromLevelOneTag(firstDBTagElement,"RoHSExemption");
String sRoHSExemption4 = getStringValueFromLevelOneTag(firstDBTagElement,"RoHSExemption");
String sRoHSExemption5 = getStringValueFromLevelOneTag(firstDBTagElement,"RoHSExemption");

thanks in advance.
regards,
Rajesh Rajaram
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's hard to tell what might be going on because we don't know what the getStringValueFromLevelOneTag method does. If its purpose it to return the first child element with the name of its second parameter, why would you expect it ever not to return the first RoHSExemption element?
 
Rajesh Rajaram
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is the method.

private static String getStringValueFromLevelOneTag(Element elementpara, String tagName){
NodeList nodelist = null;
Element element = null;
NodeList oNodelist = null;
String returnStr = null;
nodelist = elementpara.getElementsByTagName(tagName);
element = (Element) nodelist.item(0);
oNodelist = element.getChildNodes();
returnStr = nullCheck(oNodelist, element);
return returnStr;
}
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
element = (Element) nodelist.item(0);

So you are always getting the first element. You need to keep track of how many elements you have retrieved so far, e.g. by incrementing a counter and using that as the index instead of zero.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic